A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How to link a rule to a macro?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 26th 07, 06:54 PM posted to microsoft.public.outlook.program_vba
Sid
external usenet poster
 
Posts: 15
Default How to link a rule to a macro?

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.
Ads
  #2  
Old July 26th 07, 07:03 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to link a rule to a macro?

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 = ; "
rply.Send

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

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


"Sid" wrote in message ...
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.

  #3  
Old July 26th 07, 08:04 PM posted to microsoft.public.outlook.program_vba
Sid
external usenet poster
 
Posts: 15
Default How to link a rule to a macro?

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?


"Sue Mosher [MVP-Outlook]" wrote:

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 = ; "
rply.Send

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

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


"Sid" wrote in message ...
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.


  #4  
Old July 26th 07, 09:30 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to link a rule to a macro?

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


"Sid" wrote in message ...
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?


"Sue Mosher [MVP-Outlook]" wrote:

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 = ; "
rply.Send

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

"Sid" wrote in message ...
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.


  #5  
Old July 26th 07, 10:58 PM posted to microsoft.public.outlook.program_vba
Sid
external usenet poster
 
Posts: 15
Default How to link a rule to a macro?

Sue. It worked. A Million Thanks.

"Sue Mosher [MVP-Outlook]" wrote:

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


"Sid" wrote in message ...
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?


"Sue Mosher [MVP-Outlook]" wrote:

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 = ; "
rply.Send

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

"Sid" wrote in message ...
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.


  #6  
Old July 28th 07, 03:03 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 20
Default How to link a rule to a macro?

I have sought to learn the structure required to run a rule from VBA
code. Has anyone done that (short of key-stuffing)?

On Jul 26, 2:30 pm, "Sue Mosher [MVP-Outlook]"
wrote:
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.


  #7  
Old July 28th 07, 01:51 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How to link a rule to a macro?

Outlook 2007 is the first version with the capability to run a rule programmatically. Code sample at http://www.outlookcode.com/codedetail.aspx?id=1266

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


wrote in message oups.com...
I have sought to learn the structure required to run a rule from VBA
code. Has anyone done that (short of key-stuffing)?

On Jul 26, 2:30 pm, "Sue Mosher [MVP-Outlook]"
wrote:
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.


  #8  
Old July 30th 07, 04:22 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 20
Default How to link a rule to a macro?

Thank you for your clear answer, Sue.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send link to item using Folder Assistant rule sriramna Outlook - Using Forms 6 March 25th 07 06:22 PM
Server-side rule with script or macro Brian Canner Outlook and VBA 1 February 12th 07 07:59 PM
runninng macro when a rule is hit [email protected] Outlook and VBA 1 November 1st 06 03:31 PM
How do I link a macro to a CommandButton in a custom form, want us Capone2377 Outlook - Using Forms 1 February 5th 06 01:15 AM
Create a macro that runs from a Rule CF_business_analyst Outlook and VBA 8 January 13th 06 06:12 PM


All times are GMT +1. The time now is 08:37 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.