如何运行outlook';VBA的规则是什么?
我是VBA编码的新手。 我正在尝试在Outlook中创建规则,但它不起作用。我需要的工作过程是1.检测主题邮件=批准,2.检测正文邮件=批准。3.检测发件人电子邮件并最终将电子邮件发送到我的目标电子邮件 我尝试使用回复脚本使用send mail的python scrip,但它不起作用,尝试使用VBA并找到许多解决方案,但它也不起作用。请帮助我 这是我的代码:如何运行outlook';VBA的规则是什么?,vba,outlook,Vba,Outlook,我是VBA编码的新手。 我正在尝试在Outlook中创建规则,但它不起作用。我需要的工作过程是1.检测主题邮件=批准,2.检测正文邮件=批准。3.检测发件人电子邮件并最终将电子邮件发送到我的目标电子邮件 我尝试使用回复脚本使用send mail的python scrip,但它不起作用,尝试使用VBA并找到许多解决方案,但它也不起作用。请帮助我 这是我的代码: Private WithEvents Items As Outlook.Items Private Sub Application_Sta
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")
Dim oPA As Outlook.PropertyAccessor
Dim oContact As Outlook.ContactItem
Dim oSender As Outlook.AddressEntry
'==default local Inbox====================================================
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
'MsgBox ("Request for ID Document")
End Sub
Public Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
Dim xEmployer As String
Dim xLine As String
Dim xMessage As String
Dim SenderID As String
Dim SenderEmail As String
Dim xBy As String
Dim xEmail As String
Dim xFunc As Boolean
Dim xRunFile As String
Dim olAddrList As AddressList
Dim olAddrEntry As AddressEntry
Dim olExchgnUser As ExchangeUser
If TypeName(item) = "MailItem" Then
'=========================================================================
Set Msg = item
Set oPA = Msg.PropertyAccessor
SenderID = oPA.BinaryToString _
(oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C190102"))
'Obtain AddressEntry Object of the sender
Set oSender = Application.Session.GetAddressEntryFromID(SenderID)
SenderEmail = oSender.Address
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(0)
Dim OL As Object
Dim EmailItem As Object
Dim StrFileName As String
If (InStr(UCase(Msg.body), "Approve") > 0) And _
(InStr(UCase(Msg.subject), "Approve") > 0) And _
((InStr(UCase(Msg.SenderEmailAddress), "CFGFIN006") > 0)) Then
With EmailItem
.subject = "AP_Subject"
.body = "AP_Body"
.To = "my_manager_name@example.com"
.CC = ""
.BCC = ""
.Importance = 1
.Send
End With
Set Doc = Nothing
Set EmailItem = Nothing
Set OL = Nothing
SendMail = True
End If
End sub
比较文本时要更加小心 “代码>选项显式”考虑此强制 “工具|选项|编辑器”选项卡 '需要变量声明 Private with events defInboxItems As Items 私有子应用程序_启动() 将项目定义为项目 '==默认的本地收件箱项目=================================== 设置defInboxItems=Session.GetDefaultFolder(olFolderInbox).Items 端接头 Public Sub-defInboxItems\u ItemAdd(ByVal项作为对象) Dim msg作为邮件项 Dim oPA作为属性附件 将SenderID设置为字符串 将oSender设置为AddressEntry Dim SenderEmail作为字符串 将EmailItem设置为MailItem 如果TypeName(Item)=“MailItem”,则 设置msg=Item 设置oPA=msg.propertyAccessor SenderID=oPA.BinaryToString(oPA.GetProperty(“http://schemas.microsoft.com/mapi/proptag/0x0C190102")) '获取发件人的AddressEntry对象 Set oSender=Session.GetAddressEntryFromID(SenderID) SenderEmail=oSender.Address 调试。打印“SenderEmail:&SenderEmail” “如果条件允许,则中断,以便更容易地查看问题(如果有)发生的位置 如果InStr(UCase(msg.Body),(“批准”)>0,则 “你可以在任何事情上使用UCase/LCase 如果InStr(UCase(msg.Subject),UCase(“Approve”)>0,则 '您可以使用vbTextCompare 如果InStr(UCase(msg.SenderEmailAddress),“CFGFIN006”,vbTextCompare)>0,则 设置EmailItem=CreateItem(olMailItem) 使用EmailItem .Subject=“受试者” ' ... .展示 以 如果结束 如果结束 如果结束 如果结束 端接头