Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / July 2005

Tip: Looking for answers? Try searching our database.

Need help with Outlook rule option "run a script"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
XxLicherxX - 29 Jun 2005 21:21 GMT
Hello everyone,

I wish to run a custom script as part of a certain Outlook (2003) rule.

The problem is whenever I run the "create new rule" wizard and select
"run a script" nothing is listed for scripts. I don't even have browse
button to go search for the script. The only thing that comes up is a
box that has a blank window (for the scripts) and then an "OK" button
and "Close" button.

How do I add scripts to this?

Thanks
Sue Mosher [MVP-Outlook] - 29 Jun 2005 21:33 GMT
You must create a VBA procedure (not, technically, a script) first, using this syntax:

Sub MyProcedure(myMailItem as Outlook.MailItem)
   ' your code to work with myMailItem goes here
   ' for example:
   MsgBox myMailItem.Subject
End Sub

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Hello everyone,
>
[quoted text clipped - 9 lines]
>
> Thanks
XxLicherxX - 29 Jun 2005 21:58 GMT
Hi Sue,

Thanks for the response. Where do I write this procedure?

Thanks
Sue Mosher [MVP-Outlook] - 29 Jun 2005 22:28 GMT
In the Outlook VBA environment, either in the built-in ThisOutlookSession module or any regular module you want to add to the VBA project.

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Hi Sue,
>
> Thanks for the response. Where do I write this procedure?
>
> Thanks
XxLicherxX - 05 Jul 2005 21:24 GMT
Hi Sue,

I have written a simple script using Outlook's VBA editor. How do I get
this to show up in the "run a script" part of the "create a rule"
wizard?

Thanks
Sue Mosher [MVP-Outlook] - 05 Jul 2005 21:48 GMT
A VBA procedure for use with a "run a script" rule needs to be a Public Sub with a MailItem as an argument:

Public Sub MyMacro(msg as MailItem)
   Dim strID as String
   Dim olNS as Namespace
   Dim olMail as MailItem

   strID = msg.EntryID
   Set olNS = Application.GetNamespace("MAPI")
   Set olMail = olNS.GetItemFromID(strID)
   ' do stuff with olMail

   Set olMail = Nothing
   Set olNS = Nothing
End Sub

Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Hi Sue,
>
[quoted text clipped - 3 lines]
>
> Thanks
XxLicherxX - 06 Jul 2005 14:37 GMT
Thanks,

This is doing exactly what I want.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.