Hello grateful for any help here.
I have a folder ("Workbooks") which contains 5 xlsm files (this number will increase to about 62).
i have a second folder called "Master" in which i have a workbook called "Master Macro"
I have tried to create a macro in the "Master Macro" workbook which will open each file in the "Workbooks" folder then run a macro which is contained in each workbook called "refreshWS" (although refresWS is in all workbooks it is bespoke to each workbook itself so i can't have this outside of each workbook) and then close the workbook and save it - then move onto the next workbook.
However it is falling over because i am trying to run the macro in the 5 workbooks and it is saying that the macros are not enabled in the workbook- how would i get past this.
My only other thought was to open all the workbooks in one phase one of a macro and so enabling macros in each book and then once all opened run a second macro to select each open workbook and run the required "refreshWS" macro and close and save - then move onto the next open workbook (but i would somehow need to omit my "Master Macro" workbook.
Any help from you wizards with either solution would be much appreciated.
Copy of my macro below:-
Sub OpenAndRunMacroInAllWorkbooksIncludingNew()
Dim folderPath As String
Dim fileName As String
Dim wb As Workbook
' Specify the folder path where your workbooks are located
folderPath = "C:\Users\1\Workbooks\"
' Get the first file name in the folder
fileName = Dir(folderPath & "*.xls*")
' Loop through all files in the folder
Do While fileName <> ""
' Open the workbook
Set wb = Workbooks.Open(folderPath & fileName)
' Run your macro (replace "YourMacroName" with the actual macro name)
Application.Run wb.Name & "!refreshWS"
' Close the workbook (you can choose to save changes or not)
'wb.Close SaveChanges:=True
' Get the next file name
fileName = Dir
Loop
End Sub
I have a folder ("Workbooks") which contains 5 xlsm files (this number will increase to about 62).
i have a second folder called "Master" in which i have a workbook called "Master Macro"
I have tried to create a macro in the "Master Macro" workbook which will open each file in the "Workbooks" folder then run a macro which is contained in each workbook called "refreshWS" (although refresWS is in all workbooks it is bespoke to each workbook itself so i can't have this outside of each workbook) and then close the workbook and save it - then move onto the next workbook.
However it is falling over because i am trying to run the macro in the 5 workbooks and it is saying that the macros are not enabled in the workbook- how would i get past this.
My only other thought was to open all the workbooks in one phase one of a macro and so enabling macros in each book and then once all opened run a second macro to select each open workbook and run the required "refreshWS" macro and close and save - then move onto the next open workbook (but i would somehow need to omit my "Master Macro" workbook.
Any help from you wizards with either solution would be much appreciated.
Copy of my macro below:-
Sub OpenAndRunMacroInAllWorkbooksIncludingNew()
Dim folderPath As String
Dim fileName As String
Dim wb As Workbook
' Specify the folder path where your workbooks are located
folderPath = "C:\Users\1\Workbooks\"
' Get the first file name in the folder
fileName = Dir(folderPath & "*.xls*")
' Loop through all files in the folder
Do While fileName <> ""
' Open the workbook
Set wb = Workbooks.Open(folderPath & fileName)
' Run your macro (replace "YourMacroName" with the actual macro name)
Application.Run wb.Name & "!refreshWS"
' Close the workbook (you can choose to save changes or not)
'wb.Close SaveChanges:=True
' Get the next file name
fileName = Dir
Loop
End Sub