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.
/* Send e-mail to the inbox configured for the Microsoft Outlook rule described in this sample. */
/* Put the rule phrase in the -email subject to trigger the SAS Enterprise Guide batch job. */
filename outbox email to=('my-email-address@mycompany.com') subject='VBA test';
data _null_;
file outbox;
put 'Email to trigger the EG batch job.';
run;
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.
Type: | Sample |
Date Modified: | 2014-03-28 16:18:56 |
Date Created: | 2014-03-21 12:15:52 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS Enterprise Guide | Microsoft Windows Server 2003 for x64 | ||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 8.1 Pro | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft® Windows® for x64 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 |