Users Query – Hi, I am trying to download attachments from MSG files. But, because it is a very time-consuming process I am getting tired of this. So I am looking for a way to extract attachments from MSG files using VBA codes. So, if one knows the VBA code to do this then please suggest to me.
Yes, we know the manual method to download attachments from MSG is a bit long-winded process if you have orphaned .msg files. Because all you have to import all the message files into Outlook then you can able to save the attachments from it.
Therefore, w a huge number of Outlook users seeking quick and effective solutions. So if you keen to know how to save attachments from Outlook MSG files. Then you are landed on the right page here we are going to discuss full detailed steps to extract attachments from MSF files using VBA. But starting the blog let know a little bit about VBA scripting.
What is VBA Scripting?
The VBA stands for Visual Basic for Applications. Basically, it is a programming language for Microsoft Office programs. With the help of VBA codes, you achieve all the tasks which not done by the program itself.
After knowing the VBA lets jump into the blog
Extract Attachments From MSG Files Using VBA
If you and to know the VBA code to extract multiple attachments from MSG files, then there some things you have to keep in mind before starting the process. Such as the whole process is programming based so be careful while doing the steps. Because any mistakes can void your data. Now, follow the below steps in order to extract attachments from MSG files using VBA
- First, you have to import all your MSG into the Outlook program
- Now, create a folder to save all the attachments after extraction.
- After that run VBA editor to open it press Alt+F11
- Now, copy and paste the below codes in the VBA editor. Also, do some changes at the marked place
Public Sub Extract_Attachments_From_Outlook_Msg_Files()
Dim outApp As Object
Dim outEmail As Object
Dim outAttachment As Object
Dim msgFiles As String, sourceFolder As String, saveInFolder As String
Dim fileName As String
msgFiles = “C:\path\to\folder\*.msg” ‘CHANGE – folder location and filespec of .msg files
saveInFolder = “C:\path\to\folder” ‘CHANGE – folder where extracted attachments are saved
If Right(saveInFolder, 1) <> “\” Then saveInFolder = saveInFolder & “\”
sourceFolder = Left(msgFiles, InStrRev(msgFiles, “\”))
On Error Resume Next
Set outApp = GetObject(, “Outlook.Application”)
If outApp Is Nothing Then
MsgBox “Outlook is not open”
On Error GoTo 0
fileName = Dir(msgFiles)
While fileName <> vbNullString
‘Open .msg file in Outlook 2003
‘Set outEmail = outApp.CreateItemFromTemplate(sourceFolder & fileName)
‘Open .msg file in Outlook 2007+
Set outEmail = outApp.Session.OpenSharedItem(sourceFolder & fileName)
For Each outAttachment In outEmail.Attachments
outAttachment.SaveAsFile saveInFolder & outAttachment.fileName
fileName = Dir
- Once the code is pasted to the VBA editor press F5 to execute the code
- Once the execution of the VBA code is done all the attachments from MSG files is save in your allocated folder
Limitations and Consequences of VBA Method
As we said above this method contains sort of codes which is fine for a technical guy. But the whole process is useless for non-technical guys. And if any error occurs then he/she not able to find and fix it. Along with that, there are high chances of data loss during the process.
So we recommend that if you are non-technical users and didn’t know more about programming and codes then keep reading this blog because you are so close to knowing the best full proof solution to extract attachments from MSG file without writing any code or importing and data.
Quickly Export Attachments From MSG Files
Yep! You read it right in this section we are going to discuss an instant automated solution that is capable to download attachments. SysTools Outlook Attachment Extractor is an attachment management utility that gives you an option to extract attachments from Outlook PST, OST, BAK, and MSG.
Also, the tool has a very clean UI that helps both the technical and non-technical users. The advanced features of this software give the ability to save multiple attachments from Outlook emails, contacts, calendars, tasks, and journals at once.
Step to Extract Attachments from MSG Files
Download and install the software first
Once the installation is done launch the software and choose the MSG radio button and then click on the Add File(s) and Add Folder
Select the Maintain Folder Hierarchy option to preserve the folder structure
Choose the destination location to save the attachments from MSG files
After all the settings click on the Extract attachments from
Also Read : How to Fix Unable to Download Outlook Attachments
There are so many users who want to know a free method to save multiple attachments from MSG files. So that they start seeking for the solution to extract attachments from MSG files using VBA. Hence, in the write up we have discussed the step by step code to download attachments from MSG files. In addition, we also discussed the quick automated solution too so if you think the VBA code is complicated, then you can automated solution.