Results 1 to 5 of 5

Thread: Automatically Run code in Outlook when new message received

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    5

    Automatically Run code in Outlook 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
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Automatically Run code in Outlook when new message received

    there should be a message arrival event or similar that will run whenever a message arrives
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Lively Member
    Join Date
    Jun 2008
    Location
    Bayang Magiliw, Perlas Ng Silangan
    Posts
    100

    Re: Automatically Run code in Outlook when new message received

    Hit Alt-F11 keys or on outlook menu Tool -> Macro -> Visual Basic Editor

    on the right panel there are two dropdown boxes, Select Application on the first dropdown. Select NewMail <Event> on the second drop down;

    or copy paste this;

    Code:
    Private Sub Application_NewMail()
         MsgBox ("new mail")
         'insert your code here
    End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    5

    Re: Automatically Run code in Outlook when new message received

    That is very close to what I am looking for but is there anyway to go one step further and only run when a message is received in a certain folder?
    Last edited by dicepackage; Jan 28th, 2011 at 09:09 AM.

  5. #5
    Lively Member
    Join Date
    Jun 2008
    Location
    Bayang Magiliw, Perlas Ng Silangan
    Posts
    100

    Re: Automatically Run code in Outlook when new message received

    here's an idea I haven't tested this code,

    Code:
    Dim objNS As NameSpace 
    Dim objPF As MAPIFolder 
    Dim objitem As Object 
    
    'Set objNS = Application.GetNamespace("MAPI") 
    'Set objPF = objNS.Folders("YourFolder") 
    Set objitem = GetCurrentItem()
    
    
    If objitem.Parent = "<YourFolder>" Then
       :
       'insert your code here
       :
    End If

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
  •  



Click Here to Expand Forum to Full Width