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!
Solved! Go to Solution.
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:
So, when you say “multiple documents,” what types of documents are we talking about? Excel, PDF, Word? Or a mix?
Hi - apologies, I forgot to mention. It could be a mix of word, excel and pdf files.
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!
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!
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:
Fantastic - thank you!
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.
Okay. A couple things.
1) The extension holds the period.
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:
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)
User | Count |
---|---|
13 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
20 | |
17 | |
17 | |
12 | |
11 |