This question from Outlook user wanted to know how to remove several attachments from a message in one step.
I want to keep sent messages but not the attachments. Is there an easier method than clicking on the attachment to delete it? Better yet, can I select several sent messages and remove the attachments from all of the messages?
Outlook doesn't have this functionality built in so you'll need to use an add-in or VBA, but yes, it can be done.
See Attachment Management Tools for Outlook for add-ins or More Information for additional macros, including code samples that can save the attachments to the hard drive before deleting them from the message.
This code will work with sent or received messages, in any folder. To use, add the code to the VBA editor, select the messages that you want to delete the attachment from and run it.
Sub DeleteAllAttachmentsFromSelectedMessages() Dim oAttachments As Attachments Dim selItems As Selection Dim oMsg As Object Dim lngAttachmentCount As Long ' Set reference to the Selection. Set selItems = ActiveExplorer.Selection ' Loop though each item in the selection. For Each oMsg In selItems Set oAttachments = oMsg.Attachments lngAttachmentCount = oAttachments.Count ' Loop through attachments until attachment count = 0. While lngAttachmentCount > 0 oAttachments(1).Delete lngAttachmentCount = oAttachments.Count Wend oMsg.Save Next MsgBox "All Done. Attachments were removed.", vbOKOnly, "Message" Set oAttachments = Nothing Set selItems = Nothing Set oMsg = Nothing End Sub
Remove Attachments From Forwards
A user needed to forward a message, but without the attachment and with the attachment name in the message body.
As written, this works with a selected message, not an open message.
You will need to set a Reference to the Microsoft Word Object Model in Tools, References.
Public Sub RemoveForward() Dim oItem As MailItem Dim oAtt As Attachment Dim strAtt As String Dim olInspector As Outlook.Inspector Dim olDocument As Word.Document Dim olSelection As Word.Selection Set oItem = Application.ActiveExplorer.Selection.item(1) strAtt = "" For Each oAtt In oItem.Attachments strAtt = strAtt & "<<" & oAtt.FileName & ">> " Next oAtt Dim oMsg As MailItem Set oMsg = oItem.Forward oMsg.To = "alias@address" oMsg.Display Set olInspector = Application.ActiveInspector() Set olDocument = olInspector.WordEditor Set olSelection = olDocument.Application.Selection olSelection.InsertBefore strAtt For Each oAtt In oMsg.Attachments oAtt.Delete Next oAtt Set oItem = Nothing End Sub
How to Use Macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 and above, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, itâs at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
- Set a reference to the Word Object Model in the VBA editor's Tools, References dialog.
- Customize the ribbon or Quick Access Toolbar to add a button to the macro for easy access.
More information as well as screenshots are at How to use the VBA Editor
More Information
Housekeeping and Message Management Tools for Outlook
Housekeeping and Message Management Tools for Exchange Server
How to Save Email Messages to the Windows File System
VBA: Save Attachments to hard drive Can easily be tweaked to delete the attachment without saving it.
VBA: Attachments: Save the selection to the harddisk (VBOffice.net)
VBA: Attachments: Delete the selection (VBOffice.net)
How to use VBA code samples
I've come across this macro, but like another post I'd like to only delete certain files, in my case .pdf attachments. What do I need to add? I'm a complete newbie, so kindly spell it out for me. :)
I used the code "DeleteAllAttachmentsFromSelectedMessages" in Outlook 2016 and although it deleted the attachments, Outlook's list still shows the paperclip symbol.
I also tried some VBA code from another website and it did the same in Outlook 2016, that one I used in Outlook 2007 and then the paperclip symbol disappeared.
Any ideas to rectify this problem ?
I don't have a solution right now, will need to look into it.
In a quick test, the paper clip was removed. What type of email account? What is your outlook build number? Does it happen with all attachments or just some?
My email account is IMAP, with a Yahoo email address.
Tried a few different tests and all were the same, the paperclip symbol remains.
Version Outlook 2016 MSO (16.0.8326.2096) 32 bit
I made use of this script to great effect in my workflow. However, when a mailbox has multiple (nested) subfolders, navigating to each one, selecting all messages, and running the script becomes cumbersome. I took this script and modified it so that I could select the top level folder, and have it recurse into all subfolders and delete all messages' attachments. here is the modified code: ==================================================== Sub DeleteAllAttachmentsFromSelectedMessages() Dim oFolder As Outlook.Folder ' Set reference to the Selection. Can select a folder Set oFolder = ActiveExplorer.CurrentFolder ' this Sub must run in order to be recursive processFolder oFolder MsgBox "All Done. Attachments were removed.", vbOKOnly, "Message" Set oFolder = Nothing End Sub Private Sub processFolder(ByVal oParent As Outlook.Folder) Dim oMail As Outlook.MailItem Dim oAttachments As Attachments Dim lngAttachmentCount As Long ' Original selected folder as well as any recursed folders can contain mail. ' Iterate over all messages For Each oMail In oParent.Items ' Get list of Attachments for this message Set oAttachments = oMail.Attachments ' Get count of attachments for this message lngAttachmentCount = oAttachments.Count 'While there are attachments still remaining While lngAttachmentCount > 0 oAttachments(1).Delete lngAttachmentCount = oAttachments.Count Wend 'save the message oMail.Save Next 'If there are… Read more Âğ
Hi, I receive numerous emails with attachments, some come with spreadsheets as well as the copy of the spreadsheet as a pdf, and others just come with the pdf. Normally, I send the pdf only on to other parties, but for those emails that include the spreadsheet, I have to remove the spreadsheet before I send the email on. Is there a macro I can use to eliminate the spreadsheet attachment only, if it exists. I currently use another macro I found on your site to send all the emails to a specific party, but now want to add this feature to remove any spreadsheets attached with the email and keep the pdf only to forward. thanks.
You'll need to add a couple of pieces to this code, shouldn't be too bad. You'll want to filter to those emails that have > 1 attachment probably or else look for a particular subject. Then you'll need to add another IF clause to check if the file type is Excel (I usually just look for excel like extensions).
So the general concept would be something like adding this around the delete section:
Outside/above this line:
While lngAttachmentCount > 0
Add something like:
If lngAttachmentCount > 1 Then 'Or you could say = 2, if you know it's only looking for exactly 2 attachments.
Then when you are looping through the attachments, it should be as simple as this or similar:
If oAttachments(1).Name Like "*.xl*" Then
' Do the delete
End If
This is just psuedo code more or less, as I've not tested a thing.
Thanks to Diane for sharing.
Thank you! Just tried this today and it worked!
Hi Diane. So sorry to bother you again, but any luck on getting to sort out my latest question of the 6th of May?
The way the macro on this page is written, it works on selected messages -
' Set reference to the Selection.
Set selItems = ActiveExplorer.Selection
' Loop though each item in the selection.
For Each myItem In selItems
Set myAttachments = myItem.Attachments
It's not going to go through all folders or all messages - you can select one or more messages and it will only apply to those. You can (and should) test it first by copying messages to a folder.
Oh! In this case, I will patiently await your reply to my more complicated enquiry. Thanks, Diane!
My question of the 6th of May remains unanswered. Maybe Diane got sick of me, so can someone else help, please??? Basically, what I need to know is, if I upload the proposed code to be run as a Macro, can I select the folder it applies to, rather than it running on my entire Mailbox?
No, sick of you, just busy... I answer the easy comments first then work on the hard ones. I have 60+ comments waiting. :(