Is there anyway to activate and run a recorded macro to all the spreadsheets?
Strictly talking the only way to run a Google Sheets macro is through the Google Sheets UI, but macros code could be run the same way that any other Google Apps Script code.
In order to keep this answer short and helpful, forget about running the functions saved on each spreadsheet and use a "master" Google Apps Script project.
On this "master project" in a very broad sense:
- Get a list of the spreadsheets (you could use the Google Apps Script Drive Service to do this).
- Do a loop through the list of spreadsheets to do what you need to do on each of them
There are many ways to get a list of the spreadsheets. You could use a search method, get the spreadsheets that are in a folder, among other alternatives.
To do the loop, the most common way is to use a for
loop statement, but you could use other statements and Array methods, like Array.prototype.forEach
A library helps to avoid having copies of the same code on multiple places but you still have to create a Google Apps Script project an add the library as a resource.
A better alternative could be to create a G Suite Editor Add-on as they are installed once and are available on all the spreadsheets (or documents, forms, slides) for the user that installed the add-on and the users of the spreadsheets where the add-on is used.
Remarks
Usually the macros created using the macro recorder are very slow because they usually include an "activate" every time that a sheet and range was clicked during the recording, also the include activeSpreadsheet()
, activeSheet()
that should be replaced.