简体   繁体   中英

Trigger macro on email to specific folder

Error: Object not Found.

MyEmailAddress has a folder called CL and when there is something there, I want a macro called "InsertData" to run.

Dim E_flge As Byte   

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim NS As Outlook.NameSpace
    Dim MyMail As Object

    Set NS = Application.GetNamespace("MAPI")
    Set MyMail = NS.GetItemFromID(EntryIDCollection)

    E_flge = 0

    If MyMail.Class = olMail Then
    If MyMail.Parent.Parent = "MyEmailAddress" Then
            InsertData 'Macro I am trying to call
        End If
    End If

End Sub

I pretty sure you need to have a actually "Call" the macro

Call InsertData

The object not found may be in the macro itself. Perhaps you should post that

"The NewMailEx event fires when a new message arrives in the Inbox..." https://msdn.microsoft.com/en-us/library/office/ff863686.aspx "

This is the default Inbox. You likely want to reference a non-default Inbox so you cannot use NewMailEx.

Try ItemAdd along with Get reference to additional Inbox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM