Extracting all attachments from Outlook to your computer– not one by one
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
UPDATE: 2 Dec 2015 – This post has been running for over 5 years and still going strong ! Andrew Davis has submitted additional code that allows for the same filename to be saved.
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 !
Tried this and it worked a treat. Thanks. Way beyond the call of duty. Bill
Outstanding! You are brilliant – thank you for this cool tool.
can you please publish the script for this macro so that we know there are no hidden gems ??
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
Thank you very much! Worked great in Outlook 2007.
Thank you, this worked great
Excellent. Thank you!
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.
hmmm not at this stage…sorry
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…
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
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.
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?
What you can do is create a folder and put in there the messages that you want to extract the attachments from.
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)
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 !
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.
Awesome – thanks for taking the time to add to this. I am sure lots of people still use Outlook 2007.
Extremely useful macro, thanx so much!
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?
thx alot it worked great for me too office 2007
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
the folder is automatic to keep it simple and avoid complication.
thank you so much
Thankyou, saved me a lot of time and a headache!
thanks. you made my work a whole lot easier… used to extract 741 files!
OMG – you just saved my bacon!! Brilliant!!
glad I could help !
tell your friends 🙂
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!!
thanks a lot it works great…..brilliant work
You are a Gem Liron. Worked for Outlook 2010.
Hi Liron Segav, You RoCk buddy. Thanks a Ton !!!!!!!!!!!!!!!!!!!!!!!!!! 🙂
Thanks a lot sir. Nice tool I have been looking for since long back.
thank you so much finally
Thanks so much. This macro really did the job for me!
Thanks a lot………..Worked Great
Thank you.
Still working great in Outlook 2013!
FIXED IT MYSELF, THANK YOU WORKS A TREAT!
Thanks for this Macro… Saved my 479 attachments…. Initially thought Outlook was hanging. But then read the comments… Great work…
Using Outlook 2010 and getting msg: “The macros in this project are disabled. Please refer to ..user docs.. to determine how to enable macros”, when pressing “Run”. Any suggestions? thanks in advance.
Thank you so much for your help!!!!
Thanks! Great macro. One thing – it seems to freeze up on my Word Documents. Anyone else have this problem?
Never mind — worked the third time.
Works amazing on office2013 64 bit- had a lot of log reports – approx 18k+ attachments… All successfully transferred to a folder… Thanks a ton
Cant find the GetEmailAttachments.bas file…please help
you will find the line in Point number 2 that says “Right-click on this File”. It downloads a ZIP file to your computer. Then when you open the file you will fine the GetEmailAttachments.bas
I agree with everyone here. This is brilliant, and saved me so much time. Thanks heaps.
Already more than enough big-ups for this, but still felt the need to add my own. This is genius! Thanks for your efforts. I did a little amendment to handle the possibility of having more than 1 attachment with the same name (doubtless not the greatest piece of VB coding but it seems to work for me):
FileName = WheretosaveFolder & “\” & Atmt.FileName
Dim MyFile As String
Dim fileExt As Integer
Dim newFileName As String
Dim availableName As String
availableName = “N”
fileExt = 0
newFileName = FileName
Do While availableName = “N”
MyFile = Dir(newFileName)
If MyFile “” Then
fileExt = fileExt + 1
newFileName = FileName & “.” & fileExt
Else
availableName = “Y”
End If
Loop
Atmt.SaveAsFile newFileName
Thanks so much! This is awesome
I have to extract a lot of files, and this is a gem! Thank you so much.
Great tool, but I wonder if there is a simple way to add another level of functionality. I work on a Service Desk, and have users that are sent emails that have Outlook items attached to them, and within each Outlook item, there is a Word document attached, of which they need to open and print. To avoid a lengthy process and save masses of time, we were investigating using this tool to export the attachments to a folder, but it only exports the Outlook items. I was wondering if it could be tweaked in any way, to extract attachments at any level, and then export all attachments into the same folder?
This works like a gem. You are a wizard. We owe you all the beer you can handle!
Two questions BTW…
Would this extract and save something on the body in the email? E.g.:- A pic file.. like a screen shot pasted directly, not attached?
What if two or three mails have different attachments but with the same file name? What happens to the similar names ones? Do all get saved to the Folder?
Good job.. TechieGuy.
This was one of those very few occassions when I found answered, exactly what I Googled for.
Your site is awesome.
“I’ll Be Back”
Niceguy Nomore
Thank you – works well.
Brilliant Macro – saved me days of work
Brilliant thanx so much
Excellent, thank you so much for this.
For the people that have problems with the cluttered Inbox, your suggestion of splitting the messages into 350 per folder worked perfectly.
Dear Mr. Liron Segev. Thank you for sharing your code! It worked for me in Outlook 2013 exactly as is! It only took 10 minutes to extract 276 MP3s weighing in at 10.7GB! You saved me about four and a half hours of time, not to mention the astronomical mental health bills I would have acquired if I had to extract all those files manually!
Thanks again, you rock!
Suze
Thank you so much – I can now back up the attachments onto an external drive
WOW! Great job. Thank you!
At last, finally found a way to get the attached files in my email “ALL” at ones without opening each emails.
Thank you for helping. ^_^
Thanks Liron!
Awsome name!! you have saved my day 🙂
Just awesome! Thnak you! Life saver!
It works perfect when the emails are not archived. What if the email has been archived on a particular folder? It seems that it stops when I reach the archived emails.
This is just great!!!! Thanks a lot! It saved me a lot of time.
It’s great. Worked well & quick as well.
Huge thanks!
Great code! works well.
this was awesome , i had lost everything from external hardrive and thanks to this i was able to get most of my stuff back, it works
Thanks, saved me a lot of time.
Great code !!
Thanks, Just an fyi, chrome marks this download as malicious when downloading.
not sure why as the code is out here and it doesn’t do anything “malicious”. but thanks for letting us know
Thank you,,,, Bro
One thing to note if there are multiple files with the same name you only get one of them.
This is exactly why i was looking for 🙂
But can you tell me how can i use this “amendement” ? Where do i have to place it ? I have to edit the initial script ?
Thanks a lot !
Excellent! worked seamlessly with Outlook 2010. Saved me so much time!!! Thank you very much 🙂
Yes you edit the initial script. Insert the code snippet above in between “FileName = WheretosaveFolder…” and “Atmt.SaveAsFile…”. Good luck
Extremely Fantastic.
Thanks a lot. God bless u.. 🙂
I’m so beyond grateful that I could cry!! THANK YOU!!!!
We got around this by editing the VBA code as follows:
We put the “Set fso = Nothing” below the if statement:
‘ 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
Set fso = Nothing
We replaced the “FileName = WheretosaveFolder & “\” & Atmt.FileName” with the following line:
FileName = WheretosaveFolder & “\” & fso.GetBaseName(Atmt.FileName) & i & “.” & fso.GetExtensionName(Atmt.FileName)
Thanks for a great macro this saved me a lot of time.
Is there a work-around for when the attachments all have the same name? Like what Adrian pointed out?
Thank you
Shelli see my reply to Andrian today.
Hi Andrew,
Very smart indeed. The question I have is does the file up in the thread have this added VBA code in it? If not, could you be so kind as to post the updated code file that does not save duplicate attachments? I would appreciate it a lot. Thanks.
Andrew, I appreciate the quick response. Something isn’t working for me though. I added “Set fso = Nothing” after the End If in the “Show summary Message” block and replaced the line mentioned to:
FileName = WheretosaveFolder & “\” & fso.GetBaseName(Atmt.FileName) & i & “.” & fso.GetExtensionName(Atmt.FileName)
After I execute it and select the email folder that contains the attachments, I get the error:
An unexpected error has occurred.
Macro Name: GetAttachments
Error Number: 91
Error Description: Object variable or With block variable not set
I’m not familiar with VB code so it probably is something silly but I can’t see it.
Thank you in advance
Shelli
I’d be glad to but I sadly cannot attach the file as this comment field does not allow for attachments.
To the author, do you have a way that i could send this file to you or do you have a github account i can submit the changes to?
Shelli make sure you moved the “Set fso = Nothing” from the top of the code. There is one at the top and i believe that is what is causing this issue. If you just added this line than the code at the top of the file is still there….
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
Perfect! Thank you!!
This really did work brilliantly. Can you let me know why it would now say that there is an error after i used it perfectly fine yesterday?
Awesome! works for me on outlook 2013
To Author: Can Andrew send you and updated script file that you can upload for everyone’s benefit? This is to address duplicate filenames.
If author cannot post your updated file, can you consider uploading somewhere where we can download from?
To Velani: I’m was hoping to hear back from the author before I post the script because they did all the original work and I’d like for the author to host the file here. Let’s give them a bit to answer and if I don’t hear back from them i’ll find a way to post it for people to use and give credit where credit is due.
Hi Andrew, havent been following this so missed this topic. Please send me what you were looking for and I can do an update. Please also comment your bit so you have credit in the code !
email me [email protected]
I have sent the Author the updated file with my changes. Stay tuned….
Should be available on this site now.
Hi, When I run this macro I get the error message that the task can’t be performed on this type of attachment and then it seems to crash. It gives me an error number which seems to vary.
Any thoughts?
tried it on outlook 2016. Worked like a charm
I’ve got the same issue – did you manage to resolve it?
The Techguy you saved my life thank you.. but now I am getting an error that the macros on the project are disabled please refer to online help or documentation of the host application to determine how to enable macros? HELP… I love this tool.
A great script, I was able to run it on my Outlook 2007 and extract lots of attachments.
However, the script is running into an error and breaking. I can’t seem to find out which emails its worked on and which it didn’t.
Any help would be appreciated.
The error is — “An unexpected error has occurred. Please note and report the following information. Macro Name: GetAttachments. Error Number: -2147286788. Error Description: Cannot save the attachment.”
I am getting following error while running the macro. I am using Outlook 2010.
An unexpected error has occurred.
Please note and report the following information.
Macro Name: GetAttachments
Error Number: -1560264699
Error Description: Outlook cannot perform this action on this type of attachment.
the attachment may have malware, and as its parsed its found by your malware protection.
i was able to bypass the error by editing the script in the macro.
I replaced the “On Error GoTo GetAttachments_err” with “On Error Resume Next”.
This skipped the broken attachment and immediately went on to the next email.
Hello there,
I have a problem of dragging an dropping email attachments and email messages from outlook 2013 to the container filed on the solution developed in FileMaker v14. I believe its a limitation from Outlook side. Can there be an add in developed for outlook for the same purpose?
Thanks
This script works fine for me in Outlook 2013.
What I would like was a way to have it delete the attachements and replace it with a filelink to the file.
Is that possible?
try free softaken outlook pst extractor tool to extract all attachments and other items from outlook pst or ost file format
@MAX: You say it is free. Can you please post a link to the “free” softaken extractor since the one I see is a paid version.
Well written very useful article. There is a problem with the attachment removal in that it crashes on encountering a “Picture (Device Independent Bitmap)”, easiest thing is to test for atmt before trying to build the file name and skip if it is contains the string “…” above.
Its really greate! Fanks!
Awesome!!!! It works like a charm
Thank you for the macro.
I need to download attachments for the particular date….how do i do that?
Can you please share me the code for the same?
Nice one. You the best, man!! Thanks a lot!!
Hi,
This is great thanks.
Is there any way to save the file name as the Email Subject?
Regards
Veru nice!!! I love it .
Into some folders I’m having this error.
Error Nomber:-1629470715
Error description: Outlook cannot perform this action on this type of attachment”
Do you now whats happening?
Regards
Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for this macro it really helped us in the company
Your program worked like a charm…..but now I am getting the following error messages:
compile error: user-defined type not defined
and in the script: dim ns as namespace.
Any help would be appreciated. I do not know vb. thanks,
Thanks..macros help me too
When I try to create an auto rules as message arrive , I don’t see the vb module in the selection. Am I doing something wrong here?
Just want to say a big thank you. This has really helped me out.
Perfect execution: click and run!
Many thanks for taking the time to explain the world to us 🙂
Nice job.
I think I need the original macro over the update part added in. I need it to save the files as and not to add numbers onto the original file name. Other than that this is great.
I’m trying to use your macro for extracting pictures from a very large Outlook 2007 database. I’m not sure how to get into developer mode ins Outlook 2007. Your example shows how in Outlook 2010. Could you please help? thanks much
Very Thanks, my friend!!!
You just save my life!!! Over 100k extracted files!!!
Glad to hear it!
Hello all,
I hope you are doing great.
Is there a way to modify the script so it deletes only *.pdf files from the selected Outlook folder?
Thank you in advance!
Best regards,
Peter
THank you so much
Excellent stuff!
Just what I needed to grab a load of regular attachments from a mail folder.
This is genius. Thank you!
Absolute genius sir.. Very very useful.
It saved a lot of the files, but I am getting this error on most of the outlook data files folders. “Error number: -2113912827 Error Description: Outlook cannot perform this action on this type of attachment”. Do you have any ideas how to get around this?
Hi sir,
I have problem can you please arrange when extract files name same as actual file name because now creating file name with additional numbers
I have problem can you please arrange when extract files name same as actual file name because now creating file name with additional numbers please give solution
I have problem can you please arrange when extract files name same as actual file name because now creating Extratced file name with additional numbers adding please give solution
Lovely little macro does just what you say. Looking for solutions for hours via Thunderbird, Gmail, and Firefox addons. Wish I’d found this first. Thank you for work Techieguy!
Thank you very much! Life saver!!!!
Excellent Script!
This is working absolutely fine in my outlook 2013, however I need your help to further develop, I receive lot of vendor invoice in PDF via email, which we have to scan in our system, I have a drive in my company pc where if I park this PDF file, this go directly into our system, but we have to rename this PDF file in specific job number in that drive
Can you help how can macro read job number from PDF file and rename and save it in drive?
I have tried the code several times and it worked great. However Now I am faced with a problem using it. I have received several outlook item in one mail and in each outlook item is an attachment and within the attchment is the excel file. I want the code to pen each item and then each attachmentand save the excel file to my folder in my documents.
Right now when I used the current code it does save the item to my folder in my document and I need to open each and very folder to save the excel file which is tedious.
Please any help will be much appreciated.
Thanks
The VBA code I have used is as below:
‘***********************************************************************
‘* Code based on sample code from Martin Green and adapted to my needs
‘* more on TheTechieGuy.com – [email protected]
‘***********************************************************************
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”)
‘ Changes made by Andrew Davis ([email protected]) on October 28th 2015
‘ ——————————————————
‘ 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.
‘ Changes made by Andrew Davis ([email protected]) on October 28th 2015
‘ ——————————————————
FileName = WheretosaveFolder & “\” & FSO.GetBaseName(Atmt.FileName) & i & “.” & FSO.GetExtensionName(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
‘ Changes made by Andrew Davis ([email protected]) on October 28th 2015
‘ ——————————————————
Set FSO = Nothing
‘ ——————————————————
‘ 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
Hi
This script is awesome! However I am in a situation where all the emails are sent to me by my client on google and these emails(outlook emails) are saved locally on my PC. I am trying to extract the attachments in each of these emails. Can this be done locally?
Thank you for this code! I just extracted over 3,500 files.. it took some time.. 🙂 but it worked great, and saved hours of manual work!
Outlook Office365
Code works perfectly well, but didnt work for me , because I had messages with attachment that had attachment in them. So instead of saving all files that wew in there, it saved me “.msg” files in my folder which I again have to open and look for attachments inside.
I couldn’t see whether this has been answered already. I ran it for the first time and it worked to extract all attachments in my inbox. Will it keep automatically working as new emails come in? Or do I have to run it each time (and if so, will it re-download all attachments in my inbox or only the new ones)?
Thank you much the great work!
I’m getting error with code -2147286788 while running, few files saves and then stop with this error, any idea please?
Thank you so much. This worked great the first time. When I exited Outlook it asked whether I wanted to save the VBA session, i Said yes. Now no matter what I try, when I run (even after “reinstalling” the Macro) nothing happens. When i drill down, i get the “Macros are disabled” error that a couple others above were getting. Any idea how to get this to work again like the first time?
nice work, thanks
faced the same error, anyway to fix it @thetechieguy
Thanks a lot, and much more than that. You spared me days of stupid work: I had 7,500 messages with more than 5,000 attachments. Fabulous job you did.
Awesome and this scrip so you can modify as per your need 🙂
Awesome. Had some issues, but moved all emails with attachments to another folder, then ran the macro from there. 5800 attachments downloaded to my documents. I owe you a beers…
If I could, I would marry whoever wrote this. You just saved me hours and hours. Fabulous.
This was totally what I needed. I had 676 emails with attachments that I needed to get downloaded today. This did it in less than a minute!!!! Thank you very much.
Thanks for the Macro, it worked like a Champ. And I need a help to customize to set it for specific date range with time like from dd/mm/yyyy hh:mm to dd/mm/yyyy hh:mm, so that I could extract all attachments falls under this date range.
Thanks in Advance
Jay
And now, it’s not working. 🙁 “The macros in this project are disabled.” Huh?
Hi, I found all this information very useful, but as I proceeded further, got puzzeled between some steps and found them too complex for a user like me. Then on internet, I stumbled across another Tool i.e., SysTools Attachment Extractor and tried it. This tool worked surprisingly well for me as I was able to save multiple attachments from Outlook emails.
I am sure there are severally other tools on the net but are they free like this awesome code?
I absolutely love this. It’s one of the best timesaver tools I’ve come across in a long time. It even works on my Email Exchange account at work.
Thank you , this work for me.
OMG THANK YOU!! THIS IS AMAZING <3
We’re using up to date Office 365 software, and this seems to not be an included functionnality yet. I don’t quite understand why it’s not a stock outlook feature..
Fortunately I found your page and it’s working OK for me.
Saved my day. Thanks
outstanding! this also works in outlook 2016! Thanks!
Thank you so much! works perfectly in Outlook 2016!!
Duuuuude :)))))
U are awesome!!!!!
I received below error for one of email folders, kindly reply me on [email protected], Appreciate your help
“An unexpected error has occured
Please note and report the following information.
Macro Name: GetAttachments
Error Number: -1456455675
Error Description: Outlook cannot perform this action on this type of attachment.”
I am not a savvy on VBA can you tell me where can i specify files PDF or EXCEL to extract only.
This is the glory and works fantastically in Outlook 2016. Took 1 minute to set up, took 3 seconds to save all mails to folder.
thank you so much for this
2019 and still works like a charm on OFFICE 365 and windows 10
Can anyone help how to make it work in office 365 an windows 10 i have 4 pst file and 4 separate emails i need attachments from all of them in outlook.
worked so well amazing thank you so much
Hi, mine only worked for 1 day, now today when I am trying to carry on exporting attachments, it says it is disabled. Please help!!!
IS there a way to have the attachment renamed on export such that it is named according to a piece of the subject line?
I have hundreds of emails from an automated source that names every attachment the same BUT the SUBJECT line has the info on the attachment that would be PERFECT in the file name itself.
Thank you so much for this, it was of great help!
Thank you very much! very helpful!
I have a situation where I receive 100+ automated emails a month. Each email contains one Excel attachment (no text or any other content). The emails have unique branch identifiers in their subject lines (e.g. Rent Roll Monthly Report OR010, Rent Roll Monthly Report TX033, Rent Roll Monthly Report CA101). But the Excel attachments all have the exact same name (e.g. rent_roll-20190515.csv). Is there a way to revise this macro so that the file name of each saved Excel file could be the branch identifier from the email subject line? That way, I would end up with 100 Excel files, each with a name equal to its branch identifier (e.g. OR010, TX033, CA101). Thanks
I was doubtful but this worked absolutely brilliantly. Thanks buddy.
Outlook pst extractor is a simple application .This software is a multifunctional programme .This is very simple interface and easy to operate.MS Outlook Attachment Extractor Software to Extract Adobe PDF, Word DOC/DOCX, Excel XLS/XLSX and other documents quickly.This software is capable to extract pst data file attachments.
Visit at ; https://www.osttopstapp.com/extract-outlook-pst.html
Is it possible to export the emails WITH the attachments? Into an excel file?
Still works in 2020 with Outlook version Office365 ProPlus. Thanks, I get 5-6 emails a day with attachments, and was just asked to put them all in a folder. :-S
Your macro saved me DAYS of work, and to those asking to post the code. Good concept to ensure safety, but you should really inspect it after unzipping the file, and not rely on what gets posted. 😉
Thanks again.
2020 it is and this works like a charm..! Thank you. 🙂
you’re welcome! thanks for being here!
You are absolutely genius. However, may I ask you please on how to select a specific folder rather than My Documents? Thanks in advance.
Fantastic. It worked !!!! Thanks bud !!!