Consulting

Results 1 to 4 of 4

Thread: Macro to run for all incoming email as it arrives

  1. #1

    Macro to run for all incoming email as it arrives

    Hi All,

    I'm brand new to VBA, i'm trying to find a way of running a macro when an email arrives. I cant find any rule actions which allow you to run scripts (which i believe was removed in later versions for security reasons).

    How would I have a macro run every time an email arrives? I understand Outlook will always need to be open for this to even be a possibility but i'm not sure what needs to be added to the test macro below so it runs every time a new email comes in.

    Sub SayHello()
    MsgBox "Hello World!"
    End Sub

    thanks.

  2. #2
    You are going to need the scripts, which can be restored to rules - https://www.extendoffice.com/documen...t-missing.html
    Then what you want is simple
    Sub HelloWorld(olItem As Outlook.MailItem)    With olItem
            MsgBox "Hello World!"
        End With
    lbl_Exit:
        Exit Sub
    End Sub
    The macro then runs when the message arrives in the inbox.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Quote Originally Posted by gmayor View Post
    You are going to need the scripts, which can be restored to rules - https://www.extendoffice.com/documen...t-missing.html
    Then what you want is simple
    Sub HelloWorld(olItem As Outlook.MailItem)    With olItem
            MsgBox "Hello World!"
        End With
    lbl_Exit:
        Exit Sub
    End Sub
    The macro then runs when the message arrives in the inbox.
    thats perfect!!!! Thanks so much

  4. #4
    One related question, would any vb macro go inside the with, end with for it to run when an email comes in?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •