Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Run VBA code on receipt of e-mail (http://www.outlookbanter.com/outlook-vba/24867-run-vba-code-receipt-e.html)

White Horse August 23rd 06 08:15 PM

Run VBA code on receipt of e-mail
 
Can the receipt of an e-mail run a macro, and if so, could someone post
sample code?


Sue Mosher [MVP-Outlook] August 23rd 06 11:41 PM

Run VBA code on receipt of e-mail
 
One of the easiest ways is to use a "run a script" rule in Rules Wizard to run a VBA procedure with a MailItem or MeetingItem as its parameter. That item is processed by the code:


Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
MsgBox msg.SUbject

Set msg = Nothing
Set olNS = Nothing
End Sub

See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example.


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"White Horse" wrote in message oups.com...
Can the receipt of an e-mail run a macro, and if so, could someone post
sample code?


White Horse August 28th 06 09:51 PM

Run VBA code on receipt of e-mail
 
Thanks Sue! Your tip solved my problem. I'm posting a new help
request for printing image attachments. Hope I hear from you on this
one.

Mike



All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com