0

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

2 Answers2

0

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

SuperDad
  • 13
  • 4
  • http://stackoverflow.com/questions/2573597/should-i-use-call-keyword-in-vb-vba http://stackoverflow.com/questions/2573597/should-i-use-call-keyword-in-vb-vba/2582064#2582064 "I always use Call in VBA. To me, it just looks cleaner. But, I agree, it's just syntactic sugar, which puts it squarely the realm of personal preference. I've come across probably a dozen full time VBA guys in the past few years, and not one of them used Call. This had to added advantage that I always knew which code was mine. :p Nick" – niton Dec 18 '15 at 17:16
0

"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

Community
  • 1
  • 1
niton
  • 8,771
  • 21
  • 32
  • 52