web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : hFqIQl2WCKEQRW/ziKjt/x
Power Automate - Power Automate Desktop
Unanswered

Loop Saving Attachments from Emails which are stored in a folder

Like (0) ShareShare
ReportReport
Posted on 25 Nov 2021 13:16:59 by 4

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?

I have the same question (0)
  • VJR Profile Picture
    7,635 on 26 Nov 2021 at 12:13:17
    Re: Loop Saving Attachments from Emails which are stored in a folder

    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.

     

  • MichaelAnnis Profile Picture
    5,721 Moderator on 25 Nov 2021 at 21:08:05
    Re: Loop Saving Attachments from Emails which are stored in a folder

    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-a995-45d9-bde2-f331f60e2790

     

    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. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2

Loading complete