Articles → VBA FOR OUTLOOK → Call A VB Script In A Rule In Outlook

Call A VB Script In A Rule In Outlook






Prerequisite






  1. Open registry editor (using ‘regedit’ in run).
  2. Go to the following path in registry editor - Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security
  3. Change the value of ‘EnableUnsafeClientMailRules’ from 0 to 1.
  4. Picture showing registry window for setting the value of EnableUnsafeClientMailRules from 0 to 1
    Click to Enlarge

  5. Close the registry editor.

Create A VBA Script




  1. Go to the ‘Developer’ tab in outlook.
  2. Click on ‘Visual Basic’ button.
  3. Picture showing the Visual Studio button inside the developer tab
    Click to Enlarge

  4. An editor will open as shown in screen shot below
  5. Picture showing the visual basic editor for writing code
    Click to Enlarge






Sub MyMethod(Item As Outlook.MailItem)
	MsgBox "Hi"
End Sub




Picture showing the implementation of MyMethod inside the visual basic editor
Click to Enlarge


Create Rule




  1. Go to the ‘Home’ tab.
  2. Click on ‘Rules’ – ‘Create Rules…’
  3. Picture showing the Rules menu for creating new rules
    Click to Enlarge

  4. A pop-up window will appear as shown in figure below
  5. Picture showing the Create Rule window for setting the rule on subject line
    Click to Enlarge

  6. Here, you can select the any condition. For this article, I am selecting a condition – when Subject contains ‘TestTest’.
  7. Click on ‘Advanced Options…’. Following window will come
  8. Picture showing the Rules wizard when rule is created on the subject line
    Click to Enlarge

  9. Click on ‘Next’.
  10. In the next screen, select the option ‘run a script’
  11. Picture showing the action to be performed when rule criteria is met
    Click to Enlarge

  12. In the second window, click on the ‘a script’ link as shown by red border in above image.
  13. A window will appear to select the script
  14. Picture showing the list of script to be choosen for execution
    Click to Enlarge

  15. Click ‘Ok’ to close this window and click on ‘Finish’ in the parent window.

Output




Picture showing the message box which invoked when the rule criteria is met
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, October 21, 2018

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250