How to Get Macro Info from a DOCX File in Java

Cloudmersive
2 min readMar 23, 2021

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:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

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

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.90</version>
</dependency>
</dependencies>

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)
//Apikey.setApiKeyPrefix("Token");
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);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling EditDocumentApi#editDocumentDocxGetMacroInformation");
e.printStackTrace();
}

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.

--

--

Cloudmersive

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