作者:洗吉精洗白菜_773 | 来源:互联网 | 2023-05-19 16:02
下面的代码(我从几个来源中提取)现在的工作原理是,当我收到主题行中包含特定单词的电子邮件时,它会触发运行下面的脚本.
然后,此代码保留主题行,将邮件正文和转发文本添加到预期收件人.
但是,如果我收到的电子邮件有附件,则代码不再转发任何内容.我需要它来转发通过电子邮件发送给我的附件(仅使用代码将文本添加到电子邮件正文中,否则我只会设置规则).
代码如下:
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
Eugene Astaf..
6
在代码中不需要使用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入门文章很有帮助.
1> Eugene Astaf..:
在代码中不需要使用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入门文章很有帮助.