Forum Discussion
Change excel file in batch
Hi all,
I have a lot of identical files in the same folder, all born from the same template: the only difference between them is their file name and the values inserted manually in the unlocked cells of each sheet. I'm guessing if there is any way to change the formulas of each file by just changing the original one and get it all reflected at once (let's say I find out I did a mistake in some cells and want to change for all the files).
I'm up to any solution, even using power automate or some crazy script.
Really hope someone can help,
Many thanks
3 Replies
If you need to change only a few formulas, you could use the following macro as starting point. You'll have to modify it for your situation of course.
Sub UpdateFormulas() Dim fld As String Dim fil As String Dim wbk As Workbook Dim wsh As Worksheet Application.ScreenUpdating = False ' Folder path with trailing backslash fld = "C:\Excel\" ' First filename fil = Dir(fld & "*.xls*") ' Loop through the files Do While fil <> "" ' Open workbook Set wbk = Workbooks.Open(Filename:=fld & fil) ' Refer to a sheet Set wsh = wbk.Worksheets(1) ' Change a formula wsh.Range("A20").Formula = "=SUM(A1:A19)" ' Save and close the workbook wbk.Close SaveChanges:=True ' Get next filename fil = Dir Loop Application.ScreenUpdating = True End SubIf you need to change a large number of formulas, I'd prepare a worksheet with cell or range addresses in the first column, and the new formulas (as text) in the second column.
It would then be possible to use this in an expanded version of the above macro.
- ALimitiCopper Contributor
hi HansVogelaar ,
Many thanks for your reply. I forgot to add that the files are sitting on a sharepoint folder, manager by my organization with some restrictions in interacting with scripts. Is there any way I can reach the goal by using Power Automate or similar?
Thanks
I'm really sorry, but I cannot help you with that.