Consulting

Results 1 to 4 of 4

Thread: Automatically Run code when new message received

  1. #1

    Automatically Run code when new message received

    I would like to configure something in Outlook so that every time a new message arrives in a certain folder it runs a script. I have a program to parse the subject of an e-mail but it has to do this manually. Is there anyway to automate this process so that once the e-mail comes in it will run my code. Another possible but less desired solution would be to have Outlook on a timer to run my code every so often.

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    Set up the rules wizard to run your code on incoming emails. You can use the following example code:

    [VBA]Sub CustomMailMessageRule(Item As Outlook.MailItem)
    MsgBox "Mail message arrived: " & Item.Subject
    End Sub[/VBA]

    Call your custom function from within the procedure that is run by the rule.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    In the Outlook rules I do not see a message to check if a new message is in a folder, it will check for everything. Is there anyway to make it focus on a specific folder because this thing will be running constantly otherwise.

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    You may want to adapt this code instead:

    http://www.vbaexpress.com/forum/showthread.php?t=35910

    You would call your custom function from the Items_ItemAdd Event.
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

Posting Permissions

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