One of the things I do each morning is check Twitter for questions about Outlook. This morning I found this one from Meester Neek.
Someone else had already replied to the tweet suggesting that Meester Neek create a rule to handle this. Unfortunately, Outlook’s only rule condition for attachments is which has an attachment. There is no option for specifying an attachment name or type. We can still use a rule and that rule can use the which has an attachment condition, but the rule is going to have to run a script in order to determine if any of the attachments are zip files and act accordingly. The script itself is extremely simple. All it has to do is check the file name of each attachment to see if it ends with .zip. If it does, then the script will move the message to the Junk E-mail folder. Otherwise, the script does nothing. This solution should work for any version of Outlook on a PC. Note that it will not work for Outlook on a Mac, OWA, or mobile devices.
Follow these instructions to add the code to Outlook.
- Start Outlook
- Press + to open the Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects
- If not already expanded, expand Modules
- Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert → Module.
- Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
Sub MoveZipFilesToJunk(Item As Outlook.MailItem) Dim olkAtt As Outlook.Attachment 'Check each attachment For Each olkAtt In Item.Attachments 'If the attachment's file name ends with .zip If Right(LCase(olkAtt.Filename), 4) = ".zip" Then 'Move the message to Junk E-mail Item.Move Session.GetDefaultFolder(olFolderJunk) 'No need to check any of this message's remaining attachments Exit For End If Next Set olkAtt = Nothing End Sub
Creating the Rule.
- Create a new rule that fires each time a new message is received.
- Set the rule’s condition to which has an attachment.
- Set the rule’s action to run a script and select this script as the one to run.