[英]Forward Email with its attachment in Outlook 2010
下面的代码(我从几个来源中提取)现在可以工作,当我收到一封主题行中包含特定单词的电子邮件时,它会触发一个运行以下内容的脚本。
此代码然后保留主题行,在消息正文中添加文本并转发给预期的收件人。
但是,如果我收到的电子邮件有附件,则代码不再转发任何内容。 我也需要它来转发通过电子邮件发送给我的附件(仅使用代码将文本添加到电子邮件正文中,否则我只会设置规则)。
代码如下:
Sub ForwardEmail(item As Outlook.MailItem)
Dim oExplorer As Outlook.Explorer
Dim oMail As MailItem
Set oExplorer = Application.ActiveExplorer
On Error GoTo Release
If oExplorer.Selection.item(1).Class = olMail Then
Set oMail = item.Forward
oMail.Subject = oMail.Subject
oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add "email address here"
oMail.Save
oMail.Send
End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub
无需在代码中使用 Explorer 对象:
Sub ForwardEmail(item As Outlook.MailItem)
Dim oMail As MailItem
On Error GoTo Release
If item.Class = olMail Then
Set oMail = item.Forward
oMail.Subject = oMail.Subject
oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add "email address here"
oMail.Save
oMail.Send
End If
Release:
Set oMail = Nothing
Set oExplorer = Nothing
End Sub
您可能会发现Outlook 2010 中的 VBA 入门文章很有帮助。
有一个不必要的条件
If oExplorer.Selection.item(1).Class = olMail Then
这可能会导致转发被绕过。
Sub ForwardEmail(item As Outlook.MailItem)
' Dim oExplorer As Outlook.Explorer
Dim oMail As MailItem
' Set oExplorer = Application.ActiveExplorer
On Error GoTo Release
' If oExplorer.Selection.item(1).Class = olMail Then
Set oMail = item.Forward
oMail.Subject = oMail.Subject
oMail.HTMLBody = "Have a nice day." & vbCrLf & oMail.HTMLBody
oMail.Recipients.Add "email address here"
' oMail.Save
oMail.Send
' End If
Release:
Set oMail = Nothing
' Set oExplorer = Nothing
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.