cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PeterAP
New Member

Loop Saving Attachments from Emails which are stored in a folder

Hi 

 

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?

2 REPLIES 2
MichaelAnnis
Memorable Member
Memorable Member

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

 

https://support.microsoft.com/en-us/office/introduction-to-outlook-data-files-pst-and-ost-222eaf92-a...

 

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. 

VJR
Solution Sage
Solution Sage

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
Next
End If
strFile = Dir
Loop

End Sub

 

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

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,338)