How to Get Macro Info from a DOCX File in Java

Need to identify the macros within a Microsoft Word document? We’ve got you covered. The following API can be run in Java and will return information about the macros defined in your specified DOCX file. The only parameters you need to supply are the file to perform the operation on and your API key!

To kick start the API process, we first need to install the Maven SDK by adding a reference to the repository in pom.xml:


Then, we’ll add a reference to the dependency:


Once the package is installed, we can add the imports call the get macro function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.EditDocumentApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
EditDocumentApi apiInstance = new EditDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
GetMacrosResponse result = apiInstance.editDocumentDocxGetMacroInformation(inputFile);
} catch (ApiException e) {
System.err.println("Exception when calling EditDocumentApi#editDocumentDocxGetMacroInformation");

Done! To retrieve your personal API key, visit the Cloudmersive website to register for a free account. This will give you access to 800 monthly calls across our entire API library.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store