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

  • Thread starter Thread starter rob
  • Start date Start date
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.
 
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
 
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.
 
Back
Top