- Community Pick
- Experts Exchange Approved
I've seen a few requests floating around for scripts that will export or strip attachments out of emails, and so far have never encountered any high quality implementations of this feature, so I created this method with a little flavor. Whether you just want an easy way to save all attachments somewhere on your computer, or you're doing a bulk reduction of your inbox size, this script should satisfy your needs.
All you need to do is select the emails you want to export or remove attachments from, and click your new "Export Attachments" button:
Specify your file path:
Choose whether or not you want to remove attachments from the original message(s):
(Don't worry about overwriting same-named files, I have you covered):
And presto! Your attachments have been saved to the desired location:
And if you chose to strip attachments, your emails will now be conveniently prepended with the files it used to contain, their size, and a link to the path where they were saved:
Here's how you make yourself an Export Attachments feature in Outlook
- 1
Insert a New Module
You're going to be making a VBA macro for going through messages and attachments. To do this, you need to open up the VBA project for your Outlook (by pressing Alt+F11). When it opens, your window will look similar to the one in the screen shot below. Then, right click your project on the left, and click Insert, Module, as shown:
- 2
Paste in the Macro Code
The hard work has all been done for you :)
The code below takes care of all the features describe above (and more). Just copy paste it into the window, and you're almost ready to go! The code to copy in is below:
When you've pasted it in, everything should look like this. The code is pretty straightforward, so those of you who like to dig in should be able to understand and customize it at will:
- 3
Add a Button for Your Macro
Now you can close down the Microsoft Visual Basic window. You've done the hard part. Next we want to add the macro to the toolbar so that you can use it conveniently. Right click on a blank area of the toolbar as shown, and click "Customize...". This will bring up the Outlook Customize Toolbars dialogue.
- 4
Drag your Macro Onto the Toolbar
You have to find your macro and drag it onto the Toolbar now. Switch to the "Commands" tab in the dialogue, and select "Macros" from the list on the left. You should see "ExportAttachments" macro there. Select it and drag it to wherever you want it on your toolbar:
- 5
Rename the Button
You probably don't like the ugly name Outlook has given your button, so go ahead and rename it. To do this, click the "Rearrange Commands" button at the bottom of the dialogue we have open (I know - pretty unintuitive). A new dialogue will open. Click the "Toolbar" option button (instead of "Menu Bar") and find the new button you just created. When you find it, select it and click the "Modify Selection" button. Here, you can rename it to whatever you want. Here's an illustration:
If you want, you can give your button a shortcut by inserting an ampersand (&) in front of the letter you want to be the shortcut. Then when you press Alt+'That Letter', it will trigger the button. Careful, if you chose a letter that is already a shortcut (like E for the 'Edit' menu item) then you'll have to press Alt+E+E(again) to cycle through to your button.
- 6
Test it out!
Now test it out! Select one or more emails, click the button, and save out your attachments. Isn't that sharp?
A few extra notes
- If you're about to overwrite a file, the dialogue pops up to confirm the overwrite or let you change the file name. If you keep changing the name to that of a file that already exists, it will keep prompting you :)
- The code puts a nicely formatted message at the top of your emails, including all the names of removed files, and their sizes, and even the path where they were saved (as a url). You can customize this message if you edit the code.
- If you move the file after you've saved it, the link in the emails doesn't get updated (unless you do it manually), so be aware if you plan to make use of this feature to track down attachments in the future - save it where you want to store it!
- If you click cancel in the initial folder chooser dialogue, the whole routine will end. If you click cancel when picking a new name for a file that already exists, it will just skip that file and leave it attached to the email.
- If you want a button that will always strip attachments, or one that will always just save all attachments, but leave the email as is, you can easily modify this macro to not prompt you and always perform the desired action.
For instance, replacing the lines
with just
One other thing you might want to consider is changing the icon of your button. I'm sure you've noticed that that nice icon on the first page doesn't appear on its own. I created that in the same place as I renamed the button. After clicking "Modify Selection", click "Modify button icon..." and you will get a window where you can specify your own icon. This is how I designed mine:
Enjoy, and if you found this article handy, let me know and click "Yes" at the top of the page!
--
Alain Bryden
PS: If you're curious about that 'Archive Message(s)' button on my toolbar, you can check out my article about it here: How to make an 'Archive' button in Outlook
Other articles by me.
by: mwvisa1 on 2010-08-12 at 11:39:31ID: 18124
Look how much cooler my icon is, though.
Seriously, as a testament to your article, having the icon image and at a decent size I was easily able to replicate even that detail in implementing this in my system.
I love this Macro, very nicely done ...
You have my Yes vote.