window.Asc.plugin.executeMethod("SetMacros", [args], callback)


Defines the method that allows setting macros to the document.


This method should be used in the following way:

window.Asc.plugin.executeMethod("SetMacros", [data]);

Where data is a Macros object containing the data about all the macros from the document in the following form (JSON):

    "macrosArray" : "string[]",
    "current" : number

The Macros object can have the following values:

  • "macrosArray" (e.g. {"macrosArray": [{"name": "Macros1", "value": "{macrosCode}"}]}) is an array of macros codes;
  • "current" (e.g. {"current": 1}) is a current macros index.

The method returns the undefined value.

window.Asc.plugin.executeMethod("SetMacros", [{"macrosArray":[{"name":"Macros 1","value":"(function()\n{oDocument = Api.GetDocument();\noParagraph = Api.CreateParagraph();\noParagraph.AddText(\"This is a new paragraph\");\noDocument.Push(oParagraph);\n})();"},{"name":"Macros 2","value":"(function()\n{oDocument = Api.GetDocument();\noParagraph = oDocument.GetElement(0);\noParagraph.AddText(\"ONLYOFFICE Document Builder\");\noRange = oDocument.GetRange(0, 24);\noRange.SetBold(true);\n})();"}],"current":1}]);