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?
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.
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.
Tomac
986
Moderator
stampcoin
699
Super User 2025 Season 2
Riyaz_riz11
577
Super User 2025 Season 2