Reputation: 1
My coworker tried to convert all the docm files on our server to docx files by simply renaming them, however this corrupts the files. The only way to open them is by renaming them to docm then opening with word and selecting disable macros. is there any way to delete all macros from a docm file and convert it to a docx in python?
I was expecting to just remove all the VBAs and instances and references of a VBA of the doc by renaming it to a zip, however that still doesnt let me open it.
Upvotes: 0
Views: 359
Reputation: 993
Spire.Doc for Python provides the capabilities to remove macros from .docm files and convert them to .docx format. But note it dosn't support creating or executing macros.
You can install it using this pip command:
pip install Spire.Doc
Here is an example that removes macros from a .docm file and save it to a .docx file:
from spire.doc import *
from spire.doc.common import *
# Create a Document instance
document = Document()
# Load a Word docm document
document.LoadFromFile("Test.docm")
# Remove macros from the document
if document.IsContainMacro:
document.ClearMacros()
# Save the document to a docx file
document.SaveToFile("ToDocx.docx", FileFormat.Docx2016)
document.Close()
Upvotes: 0