Following up on the popular Extracting Email address from outlook folder and the How to search for folder name in Outlook, and the How to search for Outlook folder by name I have been asked the following:
“Great response and very helpful. I have one similar problem I just can’t find a resolution to …. In one of my outlook folders I have many hundreds of emails many have attachments – I want to extract all the attachments into a folder (not an outlook folder). I can do this but only one at a time. Is there any way of selecting a bunch of emails and extracting all the attachments at once?“
So I had a look at outlook and sure enough there is no simple way to extract all the attachments of every email in a folder without going through each mail one by one.
There has to be a better way !
So I wrote a little Macro that will do this for you in one simple click
As per usual: when it comes to these things, I have to add my “I take no responsibility whatsoever if this Macro doesn’t work of messes up your Outlook”
I suggest backing it up before you continue further… (gotta say this for legal reasons)
Now that you have backed up your work, please continue:
1. Open Outlook
2. Right-click on this File and save it to your computer where you can find it again. Once it is downloaded, extract the one file in there and place it in the MY DOCUMENTS folder.
3. In the ZIP file you have just downloaded is the Macro file. So now we need to Import it into Outlook.
4. Outlook 2010: You need to enable the DEVELOPER ribbon (if you haven’t already done so). It looks like this:
If you dont have it enabled, then just do the following:
Click on File, Options, Customize Ribbon and then put a Tick on the Developer on the right-hand side.
Click OK and it will appear.
5. Click on Developer and then click on Visual Basic
6. Click on File, Import File
7. Select the extracted file : GetEmailAttachments.bas and click on Open
8. Click on File, Close and Return to Outlook
You are now ready to use this !
Simple click on Developer tab, click on Macros and then Macros again, select the GetEmailAttachments and click on Run !
You will now find under your My Documents folder a new Folder called Email Attachments where all your attachments will be saved.
Hope this helps !
[…] Also you can check out the How to Exctract all Attachment from Outlook to save onto the computer – not one by one […]
By: Extracting Email Address from Outlook 2007 folder « The Techie Guy's Blog – IT translated into simple English on December 31, 2010
at 10:42 am
Tried this and it worked a treat. Thanks. Way beyond the call of duty. Bill
By: Bill Best on December 31, 2010
at 2:23 pm
Outstanding! You are brilliant – thank you for this cool tool.
By: Melanie on February 17, 2011
at 4:45 am
[…] Extracting all attachments from Outlook to your computer– not one by one: https://thetechieguy.wordpress.com/2010/12/31/extracting-all-attachments-from-outlook-to-your-compute… […]
By: Don’t get ripped off – its free: how to extract or export email address from outlook folder « The Techie Guy's Blog – IT translated into simple English on March 10, 2011
at 10:12 pm
can you please publish the script for this macro so that we know there are no hidden gems ??
By: neil on March 15, 2011
at 7:41 pm
with pleasure:
Attribute VB_Name = “GetEmailAttachments”
Option Explicit
‘***********************************************************************
‘* Code based on sample code from Martin Green and adapted to my needs *
‘***********************************************************************
Sub GetAttachments()
On Error Resume Next
‘create the folder if it doesnt exists:
Dim fso, ttxtfile, txtfile, WheretosaveFolder
Dim objFolders As Object
Set objFolders = CreateObject(“WScript.Shell”).SpecialFolders
‘MsgBox objFolders(“mydocuments”)
ttxtfile = objFolders(“mydocuments”)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set txtfile = fso.CreateFolder(ttxtfile & “\Email Attachments”)
Set fso = Nothing
WheretosaveFolder = ttxtfile & “\Email Attachments”
On Error GoTo GetAttachments_err
‘ Declare variables
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set ns = GetNamespace(“MAPI”)
‘Set Inbox = ns.GetDefaultFolder(olFolderInbox)
‘ added the option to select whic folder to export
Set Inbox = ns.PickFolder
‘to handle if the use cancalled folder selection
If Inbox Is Nothing Then
MsgBox “You need to select a folder in order to save the attachments”, vbCritical, _
“Export – Not Found”
Exit Sub
End If
””
i = 0
‘ Check Inbox for messages and exit of none found
If Inbox.Items.Count = 0 Then
MsgBox “There are no messages in the selected folder.”, vbInformation, _
“Export – Not Found”
Exit Sub
End If
‘ Check each message for attachments
For Each Item In Inbox.Items
‘ Save any attachments found
For Each Atmt In Item.Attachments
‘ This path must exist! Change folder name as necessary.
‘ FileName = “C:\Email Attachments\” & Atmt.FileName
‘if want to add a filter:
‘If Right(Atmt.FileName, 3) = “xls” Then
FileName = WheretosaveFolder & “\” & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
‘ Show summary message
If i > 0 Then
MsgBox “There were ” & i & ” attached files.” _
& vbCrLf & “These have been saved to the Email Attachments folder in My Documents.” _
& vbCrLf & vbCrLf & “Thank you for using Liron Segev – TheTechieGuy’s utility”, vbInformation, “Export Complete”
Else
MsgBox “There were no attachments found in any mails.”, vbInformation, “Export – Not Found”
End If
‘ Clear memory
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Exit Sub
‘ Handle errors
GetAttachments_err:
MsgBox “An unexpected error has occurred.” _
& vbCrLf & “Please note and report the following information.” _
& vbCrLf & “Macro Name: GetAttachments” _
& vbCrLf & “Error Number: ” & Err.Number _
& vbCrLf & “Error Description: ” & Err.Description _
, vbCritical, “Error!”
Resume GetAttachments_exit
End Sub
By: thetechieguy on March 15, 2011
at 9:42 pm
Thank you very much! Worked great in Outlook 2007.
By: xiaoda on July 14, 2011
at 12:01 pm
Thank you, this worked great
By: xinix world on August 5, 2011
at 4:18 pm
Excellent. Thank you!
By: Tom on September 20, 2011
at 12:38 pm
hi – i am using outlook 2010 – i have lots of screenshots that have the same name – this awesome macro isn’t working I think because it’s ignoring files with the same name? is there a quick way to rename the incoming files? thanks lots.
By: robert on October 20, 2011
at 4:11 am
hmmm not at this stage…sorry
By: thetechieguy on October 24, 2011
at 7:55 am
Friend, this code is great!
I use Outlook 2007 and when I run the macro for about 700 emails in a particular folder it saves 400. Am I doing something wrong?
Can you help me?
I am very grateful…
By: Ricardo on January 10, 2012
at 2:46 am
not sure as this is very personal to your circumstances. What I would probably think is that either your computer times-out or the anti-virtus is not happy with this work. What you can do is split up the emails into two folders each of around 350 mails and run it again
By: thetechieguy on January 10, 2012
at 1:43 pm
First Thanks for responding, note that this code is 10. I discovered what it was, the attachments were named like that. Prepending the “icont” and it worked. Our !!!!! this code was excellent. Congratulations.
By: Ricardo on January 18, 2012
at 6:16 am
Not too be too greedy here, but since I am not very good at VBA
I would rather it work on only selected messages – any cance of changing the code to do that?
I understand if you just ignore this?
By: politicalconversations on January 27, 2012
at 11:51 pm
What you can do is create a folder and put in there the messages that you want to extract the attachments from.
By: thetechieguy on January 29, 2012
at 9:00 pm
it really works fine, thanx
maybe you would like to know that when i used it in a folder with more than 20k attachments, it crashed
(error number: 6)
By: heringer on February 7, 2012
at 3:28 pm
yip – it wasn’t built with serious volume in mind but more of a way to show HOW to extract it and that it CAN be done.
If you have really large folders, best to split them into multiple folders and run the Macro on each.
thanks for the feedback !
By: thetechieguy on February 7, 2012
at 3:42 pm
Not too familiar with how VBA macros work, but I was able to adapt this for Outlook 2007.
Thanks so much for your help :)!
Tools->Macro->Macros (or Alt+F8)
Name the macro “GetAttachments”->Create
Import the .bas file from the download. Save.
Close VBA
Return to Outlook.
Tools->Macro->Macros->GetAttachments
(Running from the VBA environment will get the correct count, but will not actually save the files to My Documents, it appears it will only actually save to My Documents if run from the menu in Outlook)
I have an Outlook folder where I receive PDF attachments from a common scanner at work, I was trying to extract 91 files and it took a minute or two to complete the macro, where Outlook will appear unresponsive, but just be patient, especially those that appear to be trying to do more in a shot.
Anyway I found this tool helpful and I thought I’d contribute notes for those that are trying to adapt this for outlook 2007.
By: Justin on February 9, 2012
at 5:12 pm
Awesome – thanks for taking the time to add to this. I am sure lots of people still use Outlook 2007.
By: thetechieguy on February 9, 2012
at 5:44 pm
Extremely useful macro, thanx so much!
By: Jean-Pierre on March 12, 2012
at 10:58 am
Worked great! Thanks! The only thing I wish it could do is to keep the original date the attachment was sent. Any way to modify this to do it?
By: Elliot on March 23, 2012
at 7:26 pm
thx alot it worked great for me too office 2007
By: omar on May 3, 2012
at 2:40 am
[…] Extracting all attachments from Outlook to your computer– not one by one […]
By: How to search Outlook for a folder name: « The Techie Guy – Liron Segev on June 15, 2012
at 9:58 am
Awesome .. just ran it and I can actually see the attachments downloading … just a question .. can I specify the folder to store all downloaded attachments .. or is it automatic
By: Parmila on September 12, 2012
at 2:37 pm
the folder is automatic to keep it simple and avoid complication.
By: thetechieguy on September 12, 2012
at 2:54 pm
thank you so much
By: cool mop on September 30, 2012
at 3:32 pm
Thankyou, saved me a lot of time and a headache!
By: Dan on November 1, 2012
at 12:28 pm
thanks. you made my work a whole lot easier… used to extract 741 files!
By: JSeeley on November 6, 2012
at 4:42 pm
OMG – you just saved my bacon!! Brilliant!!
By: Lorna on November 21, 2012
at 4:33 pm
glad I could help !
tell your friends 🙂
By: TheTechieGuy on November 21, 2012
at 4:40 pm
I have a question, can you add to the VB Macro script the ability to tell the difference between read and unread emails and only extract the attachments from unread messages to the Specified output folder? I have users that have hundreds of faxes that are attached to emails come in daily and it takes more time to have to re-download every attachment when they run your script rather than just the ones that are attached to emails that haven’t been read yet. Other than that the script works great for what is was originally designed to do and makes it easy to implement for any beginner or novice user!!
By: Harold on December 13, 2012
at 10:50 pm