How to Extract Macro Information from a Word file in Node.JS

Cloudmersive
2 min readMar 17, 2021

While there are many advantages for businesses to use macros in Word documents, there are unfortunately some disadvantages as well. To guard against malicious macros, it can be beneficial to check the active macros in a document. The following instructions will guide you through how to use an API in Node.JS to obtain macro information from a specific DOCX file.

Our first step is to install the client by running this command:

npm install cloudmersive-convert-api-client –-save

Or, you can add this snippet to your package.json:

Or, you can add this snippet to your package.json:

Now we can configure the API key and call the function with the following code:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.EditDocumentApi();var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editDocumentDocxGetMacroInformation(inputFile, callback);

And that’s it! The document’s macro information will be returned and available for review. To retrieve your personal API key, visit the Cloudmersive website to register for a free account.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.