Select Your Region
Americas
Europe
Middle East & Africa
Asia Pacific
![]() | ![]() | ![]() | ![]() | ![]() |
Using Microsoft Outlook rules to automate actions based on e-mails received or sent is a useful tool for managing an inbox. Microsoft Outlook rules also have the ability to run a script based on a defined Outlook action. According to the Microsoft article, "How to create a script for the Rules Wizard in Outlook", this script must be written in Outlook Visual Basic for Applications (VBA). It cannot be written in Microsoft Visual Basic Scripting Edition (VBScript) or other scripting languages.
With SAS Enterprise Guide and Microsoft Outlook on the same computer, you can use these Outlook rules to execute a SAS Enterprise Guide project in batch, enabling control of project execution remotely, on-demand, or from within a stored process.
Note: This sample assumes that the SAS Enterprise Guide project can be successfully executed in batch from a VBScript file. For more information about running SAS Enterprise Guide programs in batch, see "Using SAS Enterprise Guide to run programs in batch" by Chris Hemedinger.
The Developer ribbon must be enabled in Microsoft Outlook. If it is not, then select File ► Options ► Customize Ribbon.
Open Visual Basic for Applications from the Developer ribbon. Expand Project1 ► Microsoft Outlook Objects, and then double-click on ThisOutlookSession.
Use VBA code that is similar to this code in order to execute a VBScript file.
Sub RunVBS(Item As Outlook.MailItem) Dim filenme As String filenme = "cmd.exe /C C:\path-to-file\EGScript1.vbs" x = Shell(filenme, 1) End Sub
Save the VBA project, and exit Visual Basic for Applications.
In Microsoft Outlook, select File ► Manage Rules & Alerts. In the Rules and Alerts wizard, click New Rule to open the Rules Wizard.
Select Apply rule on messages I receive, and then click Next.
On this wizard page, for Step 1, Which condition(s) do you want to check?, choose the condition or conditions that you want to apply. This sample uses the condition with specific words in the subject. For Step 2, click specific words, and then enter the phrase that will trigger the script. In this sample, the phrase is "VBA Test".
Add the words or phrases and then click OK. Click Next to continue.
On this wizard page, for Step 1, What do you want to do with the message?, select run a script. For Step 2, click a script to open the Select Script window. In this window, select the VBA script that you created previously.
Click OK to close the Select Script window, and then click Next.
On this wizard page, for Step 1, Are there any exceptions?, select any exceptions for your rule. Exceptions are not specified in this sample.
Click Next to finish setting up the rule by giving it a name, turning it on, and reviewing the description.
To test the execution of the SAS Enterprise Guide project in batch, send an e-mail to Outlook using the trigger phrase in the subject line.
Now, sending an e-mail to this Outlook account runs a SAS Enterprise Guide project on-demand. Taking this task one step further, you can create a stored process that sends SMTP email to the rule-enabled Outlook account using the EMAIL engine on the FILENAME statement to run the project on an as-needed basis. For sample stored process code, click the Full Code tab in this SAS Note.
Note: Outlook must be open and macros must be enabled for Outlook rules to be applied.
For more information about using SAS Enterprise Guide, see the SAS Enterprise Guide documentation page.
For more information about stored processes, see the SAS Stored Processes: Developer's Guide for your version of SAS.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.