Skip to main content

How to remove specific type of attachments from emails in Outlook?

Author: Xiaoyang Last Modified: 2018-05-28

Have you ever tried to remove attachments in multiple selected emails by file type in Outlook? Such as, removing all docx or png attachment files from selected emails. How could you solve this job in Outlook?

Remove specific type of attachments from emails with VBA code

Remove specific type of attachments from emails with VBA code

To remove specific type of attachments from selected emails, the following VBA code can do you a favor, please do as this:

1. Select the emails that you want to remove their specific type of attachments in the mailing list.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Then, click Insert > Module, copy and paste below code into the opened blank module, see screenshot:

VBA code: Remove specific type of attachments from emails:

Sub DeleteSpecificTypeOfAttachments()
Dim xSelection As Outlook.Selection
Dim xItem As Object
Dim xMailItem As Outlook.MailItem
Dim xAttachment As Outlook.Attachment
Dim xFileType As String
Dim xType As String
Dim xFSO As Scripting.FileSystemObject
Dim I As Integer
On Error Resume Next
Set xSelection = Outlook.Application.ActiveExplorer.Selection
Set xFSO = New Scripting.FileSystemObject
xType = ""
xType = InputBox("Attachment Type:", "Kutools for Outlook", xType, 8)
If Len(Trim(xType)) = 0 Then Exit Sub
For Each xItem In xSelection
    If xItem.Class = olMail Then
        Set xMailItem = xItem
       If xMailItem.Attachments.Count > 0 Then
            For I = xMailItem.Attachments.Count To 1 Step -1
                Set xAttachment = xMailItem.Attachments.Item(I)
                xFileType = xFSO.GetExtensionName(xAttachment.FileName)
                If InStr(xFileType, Trim(xType)) > 0 Then
                End If
            Next I
        End If
    End If
Set xMailItem = Nothing
Set xFSO = Nothing
End Sub

4. And then still in the Microsoft Visual Basic for Applications window, click Tools > References to go to the References-Project1 dialog box, and check Microsoft Scripting Runtime option from the Available References list box, see screenshot:

doc remove attach by type 1

5. Then click OK to close the dialog, now, press F5 key to run this code, and a prompt box is popped out, please enter the attachment type that you want to remove, see screenshot:

doc remove attach by type 2

6. Click OK, and all attachments with the specific type you are defined have been deleted at once, see screenshot:

doc remove attach by type 3

Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!

๐Ÿค– Kutools AI : Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

๐Ÿ“ง Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

๐Ÿ“จ Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

๐Ÿ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

๐ŸŒŸ Interface Magic: ๐Ÿ˜ŠMore Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

๐Ÿ‘ One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  ๐Ÿ•˜Show Sender's Time Zone ...

๐Ÿ‘ฉ๐Ÿผโ€๐Ÿคโ€๐Ÿ‘ฉ๐Ÿป Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Instantly unlock Kutools for Outlook with a single clickโ€”permanently free. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2



Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Awesome, I was looking for this exactly. I just made a modification to remove attachments with specific string on the name.
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations