Questions regarding my outlook (2007) macro (type mismatch and newmailex event) RRS feed

  • Question

  • Hi there,

    I wrote an outlook macro which should be triggered when i got an EMAIL in my inbox.

    Here is some of the code: 

    Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim MailStr As String, objItem As Object, mail As Object, varEntryIDs As Variant, i As Integer, Inbox As Folder, counter As Integer, new_mail As MailItem
        'Hard-Coded mail adress
        MailStr = "xx.com"
        'in case multiple mails incoming at the same time
        varEntryIDs = Split(EntryIDCollection, ",")
        For i = 0 To UBound(varEntryIDs)
            'just for test purposes
            MsgBox (varEntryIDs(i))
            'getting mail object
            Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))
            'set inbox
            Set Inbox = objItem.Parent

    On my pc this is working how it should be. On a colleagues one I get a type mismatch error in this line when the event is triggered (by an email): 

    Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))

    I dont know why, Im just binding a mailitem to an object? 

    Is there a way to check if the incoming Item is a mailobj? I just want to work with emails not meetingrequests and so on.

    Later in my code I loop through the inbox and compare the sender and subject of existing emails to the new incoming ones.

    Does this functionality interfer with rules in outlook? In my understanding newmailex works before any rules in outlook. In the case a rule moves the new mail into a different folder I guess my macro loops through the wrong inbox?



    • Edited by frucht Sunday, September 28, 2014 7:03 AM
    Sunday, September 28, 2014 7:02 AM