Showing results for 
Search instead for 
Did you mean: 
New Member

Loop Saving Attachments from Emails which are stored in a folder



I have a bunch of emails saved in a desktop folder and sub-folders, and for each of these emails, I want to open and save the attachments. I have tried using the Get Files in Folder and then desktop recorder to actually open the files and save the attachments as there doesn't seem to be a default action to be able to do that. However, I'm struggling to set this up as a loop for each item in the folder.


I appreciate it would be much easier if the emails were still in outlook, but they were saved down into a folder by someone else.


Can anybody help?

Super User
Super User

Find where your outlook folders are; there is an article here:


When it comes to PAD. After “Get Files”, copy (or move) files into a new folder inside of your Outlook folder. Now, when you start outlook, all these moved files should appear in outlook under the folder you have created. 

now you can treat them as you would if they were in your outlook and it should be very easy to get the attachments and save them where you want. 

Super User
Super User

Hi @PeterAP 


If you would like to go by the macro option use this.

It is working for me.


- Add the below macro in Excel and call via "Run Excel macro" action via PAD.

- You can also pass parameters from PAD to Excel macro

- After adding below code in Excel in the VBA editor go to Tools -> References -> Tick the box that says Microsoft Outlook xx.0 Object Library



Sub SaveOlAttachments()

Dim oOutlook As Outlook.Application
Dim msg As Outlook.MailItem
Dim att As Outlook.Attachment
Dim strFilePath As String
Dim strAttPath As String

Set oOutlook = New Outlook.Application
'path where msg files are stored
strFilePath = "C:\temp\"     'Either add a hard coded path or pass a variable coming from PAD

'path for saving attachments
strAttPath = "C:\temp1\"    'Either add a hard coded path or pass a variable coming from PAD

strFile = Dir(strFilePath & "*.msg")
Do While Len(strFile) > 0
Set msg = oOutlook.CreateItemFromTemplate(strFilePath & strFile)
If msg.Attachments.Count > 0 Then
For Each att In msg.Attachments
att.SaveAsFile strAttPath & att.Filename
End If
strFile = Dir

End Sub


After running the macro all attachments will be saved under the folder mentioned in strAttPath.


Helpful resources

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power automate tips 768x460 v2.png

Restore a Deleted Flow

Did you know that you could restore a deleted flow? Check out this helpful article.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (1,469)