Articles → VBA FOR OUTLOOK → Call A VB Script In A Rule In Outlook
Call A VB Script In A Rule In Outlook
Prerequisite
- Open registry editor (using ‘regedit’ in run).
- Go to the following path in registry editor - Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security
- Change the value of ‘EnableUnsafeClientMailRules’ from 0 to 1.
Click to Enlarge
- Close the registry editor.
Create A VBA Script
- Go to the ‘Developer’ tab in outlook.
- Click on ‘Visual Basic’ button.
Click to Enlarge
- An editor will open as shown in screen shot below
Click to Enlarge
Sub MyMethod(Item As Outlook.MailItem)
MsgBox "Hi"
End Sub
Click to Enlarge
Create Rule
- Go to the ‘Home’ tab.
- Click on ‘Rules’ – ‘Create Rules…’
Click to Enlarge
- A pop-up window will appear as shown in figure below
Click to Enlarge
- Here, you can select the any condition. For this article, I am selecting a condition – when Subject contains ‘TestTest’.
- Click on ‘Advanced Options…’. Following window will come
Click to Enlarge
- Click on ‘Next’.
- In the next screen, select the option ‘run a script’
Click to Enlarge
- In the second window, click on the ‘a script’ link as shown by red border in above image.
- A window will appear to select the script
Click to Enlarge
- Click ‘Ok’ to close this window and click on ‘Finish’ in the parent window.
Output
Click to Enlarge