How to link a rule to a macro?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I found a code on this site to save attachment to a set directroy. Works
wonderfully. Thank you.

Now if I only can link a specific oulook rules to run this Macro
automatically every time it processes a new item? Help Please.
 
Rules support a "run a script" action, which uses not an external script but 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
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
 
Sue thank you for addressing my Question.

I am kinda new to VB and did not get what you meant by below. Did you mean
that I should edit the rule to run the script below? if so, how can I setup
this script?
 
The procedure I posted is an example of the structure required to run VBA code from a rule, by invoking the "run a script" rule action. Specifically, the procedure needs a MailItem or MeetingItem as its argument, and that is the item that the code works with. You would need to use a similarly-structured procedure, substituting your code to work on a specific MailItem for the code below that works with the msg object. In other words, put your own code after the "do stuff with msg" comment, using msg as your MailItem object.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Sue. It worked. A Million Thanks.

Sue Mosher said:
The procedure I posted is an example of the structure required to run VBA code from a rule, by invoking the "run a script" rule action. Specifically, the procedure needs a MailItem or MeetingItem as its argument, and that is the item that the code works with. You would need to use a similarly-structured procedure, substituting your code to work on a specific MailItem for the code below that works with the msg object. In other words, put your own code after the "do stuff with msg" comment, using msg as your MailItem object.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
I have sought to learn the structure required to run a rule from VBA
code. Has anyone done that (short of key-stuffing)?
 
Back
Top