Detect and remove Word Macros in Java

Spire.Doc load the word document with macros, it also supports to detect if a Word document contains VBA macros and remove all the VBA macros from a word document. This article demonstrates how to detect and remove VBA macros from Word document in Java applications.

Firstly, please view the sample document with macros:

Detect and remove Word Macros in Java

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class RemoveMacro {
    public static void main(String[] args) throws Exception {

        //Load the Sample Word document.
        Document doc = new Document();

        //If the document contains Macros, remove them from the document.
        if (doc.isContainMacro() )

        //save to file
        doc.saveToFile("output/RemoveMacro.docm", FileFormat.Docm);


Effective screenshot after clear the VBA macros from word document:

Detect and remove Word Macros in Java