转发电子邮件及其在Outlook 2010中的附件 [英] Forward Email with its attachment in Outlook 2010
问题描述
下面的代码(我从多个来源提取)现在可以正常工作,当我收到主题行中带有特定单词的电子邮件时,它将触发运行以下代码的脚本。
The below code (I pulled from several sources) now works in that when I receive an email with specific words in the subject line it triggers a script that runs the below.
然后,此代码保留主题行,在邮件正文中添加文本,然后将邮件转发给预期的收件人。
This code then keeps the subject line, adds text the message body and the forwards to the intended recipient.
但是,如果我收到的电子邮件带有附件,则该代码将不再转发任何内容。我也需要它转发通过电子邮件发送给我的附件(仅使用代码将文本添加到电子邮件正文中,否则我将设置一条规则)。
However, if the email I receive has an attachment the code no longer forwards anything. I need it to forward the attachment that was emailed to me as well (only using the code to add text to body of email otherwise I would just set a rule).
下面的代码:
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对象:
There is no need to use the Explorer object in the code:
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入门文章很有帮助。
这篇关于转发电子邮件及其在Outlook 2010中的附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!