Forum Discussion
ALimiti
May 18, 2024Copper Contributor
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 cel...
HansVogelaar
May 18, 2024MVP
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 Sub
If 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.
ALimiti
May 18, 2024Copper 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
- HansVogelaarMay 18, 2024MVP
I'm really sorry, but I cannot help you with that.