3

I Have multiple spreadsheets that was copied from 1 template. Each spreadsheets works exactly the same as they were just copied from 1 template which got formulas.

Is there anyway to activate and run a recorded macro to all the spreadsheets?

I usually just copy the script of the recorded macro (if there is a change in some formulas) and go one by one to all 60 spreadsheets to paste/activate that script so it can adopt the new formula change. This way it can keep all spreadsheets uniform.

is there any way to activate the changed made in template which was recorded to all the other spreadsheets?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Z0oey
  • 31
  • 4
  • You could add a library to the template and then just update the [library](https://developers.google.com/apps-script/guides/libraries). I'm lead to believe that the library functions will run slower but I've never noticed any significant delays with them. – Cooper Jul 06 '19 at 16:17

2 Answers2

1

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:

  1. Get a list of the spreadsheets (you could use the Google Apps Script Drive Service to do this).
  2. 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.

Rubén
  • 34,714
  • 9
  • 70
  • 166
0

The "manual" (and the ugly) way is copy and paste script every time in gs of new spreadsheet. Unlike regular script, need to copy and past manifest file also (in google script window -> View -> Show manifest file). Manifest is to keep keyboard shortcuts assigned.

Liker777
  • 2,156
  • 4
  • 18
  • 25
  • but since we know how to transfer Macro with keyboard shortcut assigned, we can distribute it among sheets like other gs scripts - web app, add on (the worst way) etc – Liker777 Feb 03 '20 at 18:44