How do I call a VBA macro to process every incoming message?

R

rob

I need to call a COM component to process each incoming message. I can write
VBA to call it and get the response, but I can't find out how to invoke a VBA
function from an Outlook rule.
 
S

Sue Mosher [MVP-Outlook]

A VBA procedure to be called by a "run a script" rule action needs 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
Dim rply as Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
Set rply = msg.Reply
rply.Body = "What you want the reply to say."
rply.To = "(e-mail address removed); (e-mail address removed)"
rply.Send

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

For more examples of "run a script" rule actions, see:

http://www.outlookcode.com/d/code/zaphtml.htm#ol2002
http://www.outlookcode.com/codedetail.aspx?id=1494
 
K

Ken Slovak - [MVP - Outlook]

Public Sub Foobar(item As MailItem)
' blah, blah
End Sub

Have your rule call Foobar from the "run a script" action in the rules
wizard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top