mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
* feat: write macro-enabled documents with VBA macros, from docx/macros (#471) A document's macros, the macros option, make it a macro-enabled document (.docm): its main part has the macro-enabled content type, it has the VBA project, word/vbaProject.bin, and Packer gives it a .docm's MIME type. The events of the document the macros handle, such as Document_Open, are listed in word/vbaData.xml, as Word only runs the handlers of the events listed there. createMacros, in a new entry, docx/macros, writes the macros from VBA code: ThisDocument's, modules and class modules. It writes the VBA project as [MS-OVBA] describes, in a compound file ([MS-CFB]), without a compiled cache, so Word compiles the code when it first runs it, and lists the events ThisDocument has handlers for. A vbaProject.bin from a .docm Word saved goes in macros too, with the events it handles. Checked in Word for Mac 16.114: Document_Open runs when the document opens, and so do macros in modules that use class modules and Office's library. LibreOffice imports the modules, and the Open XML SDK validator passes the demos for each version of Office since 2010. The demos workflow now validates a .docm as it does a .docx. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix: give a character beyond U+FFFF as two ChrW in createMacros' error createMacros' error for a character Windows-1252 doesn't have said to write it with ChrW and its code point, such as ChrW(&H1F600) for an emoji. ChrW only takes a UTF-16 code unit, up to &HFFFF, so that fails in Word. The error now gives one ChrW for each code unit: the surrogate pair, ChrW(&HD83D) & ChrW(&HDE00), which Word for Mac turns into the emoji. The docs say so too. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * docs: say how to run the macros of a .docm downloaded in Word for Windows The macros docs said Word asks whether to enable a .docm's macros when it opens. Word for Windows doesn't for a file from the internet, such as a .docm a web page made with docx and the browser downloaded: it blocks its macros without an Enable Content button. The docs now say to unblock the file in its Properties, that an organization's policy can still block macros, and that Word for Mac isn't affected. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>