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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Replace Multiple Strin...
Power Automate
Unanswered

Replace Multiple Strings in Multiple Files

(0) ShareShare
ReportReport
Posted on by

Hi, I am fairly new to Power Automate. I am looking for a solution that will search for and replace multiple strings from a list (an excel file with two columns, one with old values and one with new values) in multiple documents located in a folder (local or SharePoint). Is it possible to achieve this with 'Replace text' and how? Any help would be much appreciated!

I have the same question (0)
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    So, when you say “multiple documents,” what types of documents are we talking about? Excel, PDF, Word? Or a mix?

  • Community Power Platform Member Profile Picture
    on at

    Hi - apologies, I forgot to mention. It could be a mix of word, excel and pdf files.

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    We will run through all the files and use the extension of the file to determine what actions we want to take:

     

    Get Files to %Files%

    Loop 0 to %Files.Count - 1%

        Set %Files[LoopIndex].Extension% to %Ext%

        Switch (based on) %Ext%  'If you don't know what Switch is, it is like having multiple if's and choosing a destination based on a variable.  In this case, we will set up 3 procedures, 1 for each type of extension.

            Case %Ext% = xlsx

                'next you put in the steps to manage replace functionality in Excel

                Launch Excel opening %Files[LoopIndex]%

                Send Keys {Control}(f) 'Opens the find and replace

                Send Keys {Alt}(p)  'Moves over to the replace tab

                    'now loop through all your replacement words

                    Launch Excel 'opening the replace file

                    Read Data from Excel to %ExcelData%

                    Loop 0 to %ExcelData.RowsCount - 1%

                        Send Keys {Alt}(n) 'Select the "Find What" text field

                        Send Keys %ExcelData[LoopIndex][0]%  'Format should be %Datatable[Row#][Column#] starting with 0s

                        Send Keys {Alt}(e) 'Select the "Replace with" text field

                        Send Keys %ExcelData[LoopIndex][1]%

                        Send Keys {Alt}(a) 'Replace All

                    End (Loop)  'Should loop through every replace text listed on your replace file

                Save and Close Excel (or Save As if you want to save it somewhere else)

            Case %Ext% = .docx

                'I gave you Excel, you will have to figure the other two out on your own, just follow the same logic, the hotkeys will probably just be different is all

            Case %Ext% = .pdf

                'I gave you Excel, you will have to figure the other two out on your own, just follow the same logic, the hotkeys will probably just be different is all

    End (Loop)

     

    Best of luck!

  • Community Power Platform Member Profile Picture
    on at

    Thanks @MichaelAnnis Apologies to be a pain - is it possible to share a screenshot of the actions? I get the gist of what you are doing but s I am still very new to Power Automate and not completely clear about all the actions. Thanks!

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    I moved the retrieval of the replacement text to the front, outside of any loop, so you only have to launch it the one time:

    MichaelAnnis_0-1643730900516.png

    MichaelAnnis_2-1643731007054.png

     

  • Community Power Platform Member Profile Picture
    on at

    Fantastic - thank you!

  • Community Power Platform Member Profile Picture
    on at

    Hi @MichaelAnnis - I traced the action steps you shared (just the excel for now). The script executes without an error however, no text in the excel files was replaced. Could you please cast an eye on the below and let me know if you see any issues? Many thanks again.

     

    ReplaceText Flow.png

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Okay.  A couple things.

     

    1)  The extension holds the period. 

    MichaelAnnis_0-1643820903165.png

     

    I apologize, I didn't know this; so, all your Case comments will need to be ".xlsx" ".docx" and ".pdf" instead of "xlsx" "docx" "pdf"

     

    2)  Do any of your Excel have more than 1 tab?  If so, you will need to add some more commands.  By default, the replace text is set like this:

    MichaelAnnis_1-1643820994016.png

    This means it will only work for the current tab.  If you need it to work for all tabs:

    Send Keys {Alt}(h){Down}{Enter}

     

    Just play around with what you need.  Those underlines are your indicators for {Alt}(whatever is underlined)

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard