docx
docx copied to clipboard
Docx Macros (docm)
As far as I know there is no way to include a macro in a word document and export as a .docm file.
From what I can tell, unziping a .docm gives you the raw files that are embedded in the file.
Interested to know the appetite is for an api similar to styles to allow for macro word docs.
E.g. something along the lines of:
const vbaData = fs.readFileSync('./vbaData.xml');
const vbaProject = fs.readFileSync('./vbaProject.bin');
const doc = new docx.Document({
title: 'Title',
vbaData,
vbaProject,
});
Haven't actually played around with this yet so any known info/issues would be keen to know
What is a macro? code? What is the use of it?
All the Microsoft products (Word/Excel etc) have a thing called macros which allows you to write a script (VBA or C#) to automate a task you might want to do on a file.
Handy for things repetitive stuff you might do on every file.
https://support.office.com/en-us/article/create-or-run-a-macro-c6b99036-905c-49a6-818a-dfb98b7c3c9c
I prefer the idea of adding the code in like:
const doc = new docx.Document({
title: 'Title',
scripts: ['visual basic code'],
});
Rather than injecting the entire xml file in, but I don't know, may need to do more research
Agree that'd be nicer, but I think the code is baked into a project file. Will do some investigation and report back.