我正在尝试向 Outlook 中的规则添加自定义操作,其中邮件会自动转发并且附件会保留,但原始正文会被删除。
我需要为“清除内容”部分编写代码。到目前为止有以下内容:
Public Sub MyMacro(msg As MailItem)
Dim strID As String
Dim olNS As NameSpace
Dim olMail As MailItem
strID = msg.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
With olMail.HTMLBody = " "
End With
Set olMail = Nothing
Set olNS = Nothing
End Function
在 .HTMLBody 之后我无法删除任何东西。
编辑:添加了隐藏在评论中的实际要求。“我需要删除原始电子邮件内容,包括发件人。基本上这样它看起来就像一封全新的电子邮件。”
答案1
“With”语句允许您在一个块中引用一个对象(在本例中为 olMail)的多个属性。
由于您只设置一个属性,因此无需使用“With”块。因此,请尝试不使用“With/End With”语句,只使用olMail.HTMLBody = ""
,然后删除该End With
行。
答案2
无法看到代码如何在 with 语句的情况下执行任何操作,并且
民众子并结束功能
注意:代码未经测试。可能存在拼写错误和其他问题。
Public Sub MyMacro(msg As MailItem)
Dim strID As String
Dim olNS As NameSpace
Dim olMail As MailItem
Dim olMailFwd as Mailitem
strID = msg.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
'With olMail
' .HTMLBody = " "
'End With
Set olMailFwd = olMail.Forward
With olMailFwd
.HTMLBody = ""
.subject = olMail.subject ' No FW:
.To = "[email protected]"
end with
olMailFwd.display
' after initial testing change to
' olMailFwd.Send
Set olMailFwd = Nothing
Set olMail = Nothing
Set olNS = Nothing
End Sub
除非您还有更多未分享的内容。
Public Sub MyMacro(msg As MailItem)
Dim olMailFwd as Mailitem
Set olMailFwd = msg.Forward
With olMailFwd
.HTMLBody = ""
.subject = msg.subject ' No FW:
.To = "[email protected]"
end with
olMailFwd.display
' after initial testing change to
' olMailFwd.Send
Set olMailFwd = Nothing
End Sub