docx icon indicating copy to clipboard operation
docx copied to clipboard

Docx Macros (docm)

Open mmdonaldson opened this issue 5 years ago • 4 comments

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

mmdonaldson avatar Dec 09 '19 01:12 mmdonaldson

What is a macro? code? What is the use of it?

dolanmiu avatar Dec 09 '19 02:12 dolanmiu

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

mmdonaldson avatar Dec 09 '19 02:12 mmdonaldson

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

dolanmiu avatar Dec 09 '19 03:12 dolanmiu

Agree that'd be nicer, but I think the code is baked into a project file. Will do some investigation and report back.

mmdonaldson avatar Dec 09 '19 03:12 mmdonaldson