How to create a script for the Rules Wizard in Outlook

Article translations Article translations
Article ID: 306108 - View products that this article applies to.
This article was previously published under Q306108
Expand all | Collapse all

SUMMARY

The Outlook Rules Wizard allows you to "run a script" when you create a specific rule. As a developer, this allows you to perform an action on incoming mail that is not possible using the regular features of the Rules Wizard.

MORE INFORMATION

IMPORTANT: Although the Rules Wizard refers to the custom code as "script," you must create the code in Outlook Visual Basic for Applications, not in Microsoft Visual Basic Scripting Edition (VBScript) or other scripting languages such as Microsoft JScript. Also, Outlook Visual Basic for Applications is not designed to be deployed, so deployment of this custom code requires manual configuration on each user's computer. You cannot create the custom code in an Outlook COM Add-in. For additional information about limitations related to distributing Visual Basic for Applications projects, click the following article numbers to view the articles in the Microsoft Knowledge Base:
290779 Description of managing and distributing Outlook 2002 Visual Basic for Applications (VBA) projects
290780 OL2002: Code Does Not Work After Distributing VBA Project
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS To implement the custom code to process the message, create a subroutine in Visual Basic for Applications. The name of the subroutine does not matter, but it must accept one argument because the Rules Wizard will pass a mail message (MailItem) or meeting request (MeetingItem) to the subroutine. The argument must by of type MailItem or MeetingItem, otherwise the subroutine will not be available in the Rules Wizard. You cannot create one subroutine to handle both types of items by defining the argument to be of type Object. The following Outlook Visual Basic for Applications code illustrates how to create the subroutines:
Sub CustomMailMessageRule(Item As Outlook.MailItem)
   MsgBox "Mail message arrived: " & Item.Subject
End Sub

Sub CustomMeetingRequestRule(Item As Outlook.MeetingItem)
   MsgBox "Meeting request arrived: " & Item.Subject
End Sub
				
You can put the subroutine in any module, including ThisOutlookSession, but if you move the subroutine to another module or change the subroutine's name, you must modify the rule to point to the updated subroutine.

Another example of creating a custom script is located at the following third-party Web site:
http://www.outlookcode.com/article.aspx?id=62
The third-party products that are discussed in this article are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.

REFERENCES

For additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:
287530 OL2002: Questions About Custom Forms and Outlook Solutions

Properties

Article ID: 306108 - Last Review: October 6, 2011 - Revision: 6.0
APPLIES TO
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Office Outlook 2003
  • Microsoft Outlook 2010
Keywords: 
kbscript kbdswnet2003swept kbhowto KB306108

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com