Create Outlook - Script

  • Thread starter Thread starter Test
  • Start date Start date
A macro is, by definition, a public subroutine with no arguments. A "script" for use with a "run a script" rule needs to have an argument -- a MailItem or MeetingItem. That item is the item that triggers the rule and is processed by the code. Here's an example:


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 another example of a "run a script" rule actions, see:

http://www.outlookcode.com/codedetail.aspx?id=1494

CAUTION: Using this technique has been known to result in corrupt VBA code. Be sure to export your code modules or back up the VBAProject.otm file.
 
Thanks, it is working

A macro is, by definition, a public subroutine with no arguments. A "script"
for use with a "run a script" rule needs to have an argument -- a MailItem
or MeetingItem. That item is the item that triggers the rule and is
processed by the code. Here's an example:


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 another example of a "run a script" rule actions, see:

http://www.outlookcode.com/codedetail.aspx?id=1494

CAUTION: Using this technique has been known to result in corrupt VBA code.
Be sure to export your code modules or back up the VBAProject.otm file.
 
Back
Top