Outlook is set to block the attachments with specific file types, such as “.exe”, “.bat” or “.mdb” file. This article will teach you how to block and unblock specific file types in attachments via Outlook VBA.
By default, Outlook is able to auto block the attachments with specific file types like “.exe” or “.bat”, etc. More specifically, for instance, when you try to attach such files to an email, you will get a warning. Plus, if you receive any emails with such attachments, the files are hidden with an alert by default. So you aren’t permitted to view them. In this case, you may desire to unblock them. Moreover, when you find some additional unsafe file types, you may wish to block them as well.
Actually in my previous articles “How to Block Customized File Types in Outlook Attachments” and “What to Do If Outlook Blocks Your Email Attachments?”, you can learn the general way to block and unblock attachments. That is to manually change the registry keys when you hope to block or unblock attachments. It is a bit troublesome. Therefore, here we will expose you a piece of VBA code that can directly block or unblock specific file types without requiring you to edit registry keys manually.
Block & Unblock Attachments with Specific File Types
- In the first place, launch your Outlook application.
- Then press “Alt + F11” keys in the main Outlook window.
- Next in the Outlook VBA editor, open an empty module.
- Subsequently, copy and paste the following VBA code into this module.
Public objWsShell As Object Public strRegValue As String Public strFileType As String Sub UnblockAttachment() Dim strRegKeyforUnblock As String strRegKeyforUnblock = "HKCU\Software\Microsoft\Office.0\Outlook\Security\Level1Remove" Set objWsShell = CreateObject("WScript.Shell") strFileType = InputBox("Type the specific file type to be unblocked, such as " & Chr(34) & ".exe" & Chr(34) & " or " & Chr(34) & ".mdb" & Chr(34) & "and so on", "Specify File Type") 'Change the value of the registry key "Level1Remove" based on whether it has existed If RegKeyExists(strRegKeyforUnblock) = True Then strRegValue = objWsShell.RegRead(strRegKeyforUnblock) strRegValue = strRegValue & ";" & strFileType objWsShell.RegWrite strRegKeyforUnblock, strRegValue Else objWsShell.RegWrite strRegKeyforUnblock, strFileType, "REG_SZ" End If MsgBox "Unblock Successfully! Now restart your Outlook to recheck the attachments!", vbExclamation End Sub Sub BlockAttachment() Dim strRegKeyforBlock As String strRegKeyforBlock = "HKCU\Software\Microsoft\Office.0\Outlook\Security\Level1Add" Set objWsShell = CreateObject("WScript.Shell") strFileType = InputBox("Type the specific file type to be blocked, such as " & Chr(34) & ".pdf" & Chr(34) & " or " & Chr(34) & ".doc" & Chr(34) & "and so on", "Specify File Type") 'Change the value of the registry key "Level1Add" based on whether it has existed If RegKeyExists(strRegKeyforBlock) = True Then strRegValue = objWsShell.RegRead(strRegKeyforBlock) strRegValue = strRegValue & ";" & strFileType objWsShell.RegWrite strRegKeyforBlock, strRegValue Else objWsShell.RegWrite strRegKeyforBlock, strFileType, "REG_SZ" End If MsgBox "Block Successfully! Now restart your Outlook to recheck the attachments!", vbExclamation End Sub Function RegKeyExists(strCurRegKey As String) As Boolean On Error GoTo ErrorHandler objWsShell.RegRead strCurRegKey RegKeyExists = True Exit Function ErrorHandler: RegKeyExists = False End Function
- Later, for future convenience, you can add both of the “UnblockAttachment” and “BlockAttachment” subroutines to ribbon or Quick Access Toolbar.
- Eventually, you can have a try.
- Just click either macro button in Quick Access Toolbar or ribbon.
- Next you can input the specific file type to be blocked or unblocked.
- After inputting the file type, hit “OK”.
- Then, you’ll get a message prompting successful blocking or unblocking. You can restart your Outlook to activate the changes.
- Finally you can see the effects, like the screenshot below:
Beware of Potentially Insecure Attachments
Although you can unblock attachments at will by the above method, you still keep cautious. Since many viruses are powerful to disguise them as innocuous objects, if you readily unblock them, you’ll put your Outlook data into danger. Once your Outlook data gets compromised, you will leave no stones unturned to try Outlook recovery. It can be considerably troublesome and difficult unless you recur to an experienced tool, like DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql recovery and outlook repair software products. For more information visit www.datanumen.com