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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Save Excel Document in...
Power Automate
Answered

Save Excel Document in specific Folder OneDrive

(1) ShareShare
ReportReport
Posted on by 98

Hi,

I am working on a flow where I want to save an Excel document in a specific folder. However, this folder changes depending on the project number. The folders are sorted by project number, and I have this number as a variable. I want the flow to find the folder corresponding to the project number, for example, "01267", and then save the document in the subfolder "ExceldocumentProject" within that folder.

In other words, based on the project number, the correct folder should be found. So if there is a folder with the number "01267", the subfolder within it should be selected.

Do you have any idea how this can be achieved?

  • Riyaz_riz11 Profile Picture
    4,219 Super User 2026 Season 2 on at

    Hi @Anonymous34 ,

     

    You can try to use switch condition based on input number you can set.

    If you have more numbers, then try to use like one config excel file and based on number get the appropriate folder name.


    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    Regards,
    Riyaz

  • Anonymous34 Profile Picture
    98 on at

    Hi, 

    Thanks for your response!

    The project number that keeps changing is user input. Therefore, I can't put it in an Excel file and iterate from there. The project number is manually entered by the user, which then initiates this flow and is stored in a variable.

    The folders where I need to store an Excel document always start with the project number, and below that are a number of subfolders.

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Anonymous34 

     

    You are trying to achieve this in desktop flow or clod flow?

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Anonymous34 Profile Picture
    98 on at

    Hi @Deenuji,

    In Desktop flow 🙂 

  • NathanAlvares24 Profile Picture
    1,714 Moderator on at

    Hi @Anonymous34 !

     

    You can try this simple flow.

     

    NathanAlvares24_13-1719935644300.png

    NathanAlvares24_14-1719935662026.png

    NathanAlvares24_15-1719935684413.png

     

    Initialize an input variable which you can trigger from outside and you just have to type the project number in that field.

    NathanAlvares24_3-1719934746394.png

     

    Type your project number here to run:

    NathanAlvares24_5-1719934839893.png

     

    So what this flow actually does is that, I launch an empty excel file (or maybe an already existing one but you can modify it accordingly), I do some processing for the excel file noted in the comments. Then I simply list out all the folders in that main directory. A list of folders will be produced. Iterate through each using for each loop. Check the condition if the name of the folder is containing the input variable value. If yes, get the subfolders within this project folder, I guess its always going to be "ExceldocumentProject". So you can index it to just the first folder given by index 0. Then save the excel file as:

    NathanAlvares24_6-1719934969696.png

     

    Then close the excel as the "save document" and exit the loop because its doing for one excel file and once it got the folder, no need to keep iterating over and over.

     

    Additionally, I added a boolean variable to keep check incase if you don't get the project folder. So if you get the folder, make it true and exit from the loop.

    But if not found, i.e. it is still false, save the excel file as the same pic above and close the excel as the "save document".

     

    My project folders and in each of them already there is a subfolder named "":

    NathanAlvares24_7-1719935203123.png

     

    NathanAlvares24_8-1719935215568.png

     

    First round (incase if project folder doesn't exist):

    Input:

    NathanAlvares24_9-1719935247734.png

     

    Output:

    NathanAlvares24_10-1719935279652.png

    NathanAlvares24_11-1719935297371.png

     

    Second Round (the case if project folder already and subfolder already exists and just save it there):

    Input:

    NathanAlvares24_12-1719935394278.png

     

    Output:

    NathanAlvares24_16-1719935801194.png

     

    Third Round (the case if project folder already exists but its subfolder doesn't exist and just save it there):

    I guess you got the point here as well.

     

    Code (just copy-paste this code into your flow) :

     

    SET MainFolderPath TO $'''C:\\Users\\Username\\Desktop\\ProjectFolders'''
    SET boolFoundFolder TO False
    Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance
    # ##########################################################################################
    # Add the process part for excel here
    # ##########################################################################################
    Folder.GetSubfolders Folder: MainFolderPath FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Folders
    LOOP FOREACH Folder IN Folders
     IF Contains(Folder.Name, varProjNumber, True) THEN
     Folder.GetSubfolders Folder: Folder FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> SubFolders
     IF IsEmpty(SubFolders) THEN
     Folder.Create FolderPath: Folder FolderName: $'''ExceldocumentProject''' Folder=> NewSubFolder
     Excel.SaveExcel.SaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''%NewSubFolder%\\%varProjNumber%'''
     ELSE
     Excel.SaveExcel.SaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''%SubFolders[0]%\\%varProjNumber%'''
     END
     Excel.CloseExcel.CloseAndSave Instance: ExcelInstance
     SET boolFoundFolder TO True
     EXIT LOOP
     ELSE
     NEXT LOOP
     END
    END
    IF boolFoundFolder = False THEN
     Folder.Create FolderPath: MainFolderPath FolderName: $'''%varProjNumber%_ProjectFiles''' Folder=> NewFolder
     Folder.Create FolderPath: NewFolder FolderName: $'''ExceldocumentProject''' Folder=> NewSubFolder
     Excel.SaveExcel.SaveAs Instance: ExcelInstance DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''%NewSubFolder%\\%varProjNumber%'''
     Excel.CloseExcel.CloseAndSave Instance: ExcelInstance
    END

     

     

     

    I hope this helps.

  • Anonymous34 Profile Picture
    98 on at

    Hi @NathanAlvares24,

    Thanks for your response! It works somewhat and also saves it but not where I want it. Where I eventually want it to save it is in the a subfolder of a subfolder. I will explain with screenshots.

    I have here below the Projectnumber

    Anonymous34_0-1720436760766.png


    Then i want the open the folder that contains 02698 ( this works 🙂 )

    Anonymous34_1-1720436813433.png


    Then i want in these map to open the folder that contains "Verslagen" (see screenshot)

    Anonymous34_2-1720436915015.png

     

    And in these folder i want to save the excel document in "01 Bouw(team)vergadering"

    Anonymous34_3-1720436964476.png

    Thanks in advance for your help!

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    If you're syncing the OneDrive directory to your machine via the OneDrive app, you can use Get subfolders in folder action to get the subfolders and use the project number in the filter. This will return the one folder for your project. Then you just use the first item in the returned list as a part of the path, and specify any remaining folders inside it additionally in the Save Excel action, or Move file(s) action, if you don't have the Excel document open.

     

    The loop that @NathanAlvares24 is absolutely unnecessary, because what they did was simply put a * in the folder filter in Get subfolders in folder, when you could have really just used %varProjectNumber%*  as the filter there to only return the one folder you need.

  • Anonymous34 Profile Picture
    98 on at

    Hi @Agnius,

    Thank you for your response. 🙂

    What exactly do you mean? I did the activity Get subfolders in folder with the filter of Project Number. But what are the actions after that, because how do I finally get into the subfolders and then save the excel document?

    Anonymous34_1-1720445055927.pngAnonymous34_2-1720445104368.png



    Thank you!

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    %Folders% is a list of folders. %Folders[0]% will return the first item, and %Folders[0].FullName% is the full path to it. But that's just the project folder, so you need to add the remaining bits to it in the Save Excel action. Assuming they're static, you can use this:

    %Folders[0].FullName%\008 - Verslagen\01 Bouw(team)vergadering\{somefilename}.xlsx

  • Anonymous34 Profile Picture
    98 on at

    Hi @Agnius,

    It works! Thank you so much. I just couldn't figure it out! Thank you!! 😁

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 430

#2
11manish Profile Picture

11manish 341 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 282

Last 30 days Overall leaderboard