【发布时间】:2020-12-08 23:51:57
【问题描述】:
我正在尝试将电子邮件从我公司的 Outlook 转发到我们公司以外的电子邮件帐户。我已获准这样做。
我想转发主题行中包含“Excel Friday”的任何电子邮件。
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
' default local Inbox
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(Item) = "MailItem" Then
Set Msg = Item
If Msg.Subject = "Excel Friday" Then
Dim myMail As Outlook.MailItem
Set myMail = Msg.Reply
myMail.To = "xxxxxx@fakemail.com"
myMail.Display
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
【问题讨论】:
-
仅供参考,您可以使用基本的 Rules & Alerts 规则来做到这一点
-
为什么需要使用 VBA 宏? Outlook 允许手动完成工作。