Cookies help us deliver our services. By using our services, you agree to our use of cookies.
Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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

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
                    xAttachment.Delete
                End If
            Next I
            xMailItem.Save
        End If
    End If
Next
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



Kutools for Outlook

More than 100 Advanced Functions for Outlook 2010, 2013, 2016, 2019 and 365

screen shot kutools for outlook tiny for banner 201812

More Features  |  Free Download  |  Only $39.00 for hundreds of functions

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.