Search code examples
vbaoutlookoutlook-2010autostart

Autoforward Macro Outlook 2010 VBA does not fire on Outlook Start "Updating Folders"


Windows 7, Outlook 2010 Exchange.

I have an autoforward macro for incoming email that works flawlessly in forwarding all incoming email items to an external account I need for consolidation.

The only issue is every time I cold boot and START Outlook, the items that appear after the usual "Updating this folder..." in the ticker do NOT autoforward. From that point forward the macro starts working perfectly again.

It is located in the ThisOutlookSession.

In previous Outlook versions, a rule that ran a similar macro always fired upon startup.

Thanks for any help.

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim varEntryIDs
    Dim objItem
    Dim myItem As MailItem
    Dim i As Integer
    varEntryIDs = Split(EntryIDCollection, ",")
    For i = 0 To UBound(varEntryIDs)
        Set objItem = Application.Session.GetItemFromID(varEntryIDs(i))

        If TypeOf objItem Is MailItem Then                     

            Set myItem = objItem.Forward
            myItem.Recipients.Add "[email protected]"

            myItem.DeleteAfterSubmit = True                    
            myItem.Send
            Set myItem = Nothing
        Else
            Debug.Print "Skipping " & TypeName(objItem)
            Set myItem = Nothing
        End If
    Next
End Sub

Solution

  • Try to set up a rule which calls a macro sub instead of handling the NewMailEx event.

    If you are running Exchange in non-Cached mode the event will only fire as long as Outlook is running when a new e-mail arrives. If you close and re-open Outlook, all the e-mails that were in the queue waiting to be delivered will appear in Outlook but the event will not fire. This is a well-known issue in Outlook.

    You can read about all possible ways for handling incoming emails in the Outlook NewMail event unleashed: the challenge (NewMail, NewMailEx, ItemAdd) article.