2015年10月26日星期一

Outlook+VBA: How to delete Auto-forwarded emails using outlook rule and VBA?

There is not condition for Auto-forwarded when you try to create a new rule in Outlook, so you have to run a script when an email arrives.

1) Press Alt+F11 to open VBA (VbaProject.OTM) on Outlook 2010.
2) Create a procedure. Copy and paste below coding in your VBA.
Sub DeleteAutoForwardedEmail(Item As Outlook.MailItem)
   If Item.AutoForwarded Then
      Item.Delete
   End If
End Sub
vba
3) Save and exit VBA.

4) Create a new rule on Outlook 2010.
5) Start from a blank rule: Select “Apply rule on messages I receive” -> press Next
6) Which condition(s) do you want to check? Select nothing or “on this computer only” -> press Next.
7) What do you want to do with the message? Select “run a script”.
8) Use mouse to click “run a script” in “Edit the rule description” box, and select “Project1.ThisOutlookSession.DeleteAutoForwardedEmail”. -> press Next.
9) Press Next to ignore “Are there any exceptions?”.
10) Assign a name for this rule: Delete AutoForwarded Email.
11) Press Finished.

rule



Before to run the script, you need to enable macros in Outlook.

1) File -> Options -> Trust Center -> Trust Center Settings
2) Macro Setting -> Select "Enable all macros (not recommended; potentially dangerous code can run)".
3) Press OK and re-start Outlook.

enablemacro



沒有留言:

發佈留言