Link to home
Start Free TrialLog in
Avatar of will_scarlet7
will_scarlet7

asked on

Autorun MACRO on Send & Recieve...

Is there a way to trigger a MACRO to run automaticaly after every send & recieve?
Avatar of stefri
stefri
Flag of France image

Private WithEvents olInboxItems As Items
Dim objNS As NameSpace


Private Sub Application_Startup()
  Set objNS = Application.GetNamespace("MAPI")
  Set olInboxItems = objNS.GetDefaultFolder(olFolderOutbox).Items
End Sub

Private Sub Application_Quit()
  Set objNS = Nothing
End Sub

' sending mails function
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' your code
End Sub

' receiving mails function: items aded to inbox items collection
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)

  On Error Resume Next

  If Item.Class = olMail Then
      ' your code
  End If
 
End Sub
stefri
Avatar of will_scarlet7
will_scarlet7

ASKER

ThanX Stefri! Looks good in theory. I'll test it out later today and let you know how it goes. Do you know if I can set this to a folder other that inbox as well?
ASKER CERTIFIED SOLUTION
Avatar of stefri
stefri
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I super appreciate it! I'll let you know how it goes when I test it later.

ThanX!

Sam
ThanX for your help! It worked beautifully.

God bless!

Sam
Are you still partricipating in the EE Stefri?
not really....
Am I missing you?
I switch job position 6 months ago (still the same company) from Messaging system to HR system....
I was accustomed to appliance failures, not to people failure: HR network has bottleneck, and looks like a NFS server: not responding...still trying....

That is why I had no time to come to EE and participate to threads
I shall try to hook up again

Stefri
Hi,
If you have the time and are still interested in Outlook programming I would appreciate any thoughts you have on the following question:
https://www.experts-exchange.com/questions/21497211/Stefri-Logic-question-re-creating-a-MACRO-to-sort-sent-emails-to-user-selected-folders.html

From when I first started learning Outlook events and automation you were the one who helped me the most, so I value any insight you might have.

Sam