email - Trigger VBA code to run after a new mail is received in Outlook? -


win 7, outlook 2013 use vba code takes action on of files arrive in inbox. however, have click/run button run macro.

is there way code run automatically when email arrives?

i have tried outlook rule run script not successful.

i tried this, works when once run macro

private sub application_newmail()     call getattachments_from_inbox (my macro) end sub 

i use script run rule, applied messages. gives easy , clear access mail item receive. since want run on each message setting withevents on inbox probably best bet.

for example:

you can create listeners outlook folder follows:

private withevents maininboxitems outlook.items  public sub application_startup()      dim olapp outlook.application     dim objns outlook.namespace     set olapp = outlook.application     set objns = olapp.getnamespace("mapi")      set maininboxitems = objns.folders("whatever main mailbox called").folders("assignnumber").items     'assumes "assignnumber" folder subfolder of main inbox     'otherwise can nest folders("myarchive").folders("assignnumber).items etc end sub 

you can many folders want, too.

you can assign itemadd method each of them like:

private sub maininboxitems_itemadd(byval item object) 'do stuff mailitem  call getattachments_from_inbox (item) end sub 

all code can go in thisoutlooksession.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -