Files
DolanandClaude Opus 5.5 ea08b9677c feat: write macro-enabled documents with VBA macros, from docx/macros (#471) (#3791)
* 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>
2026-10-19 00:13:28 +01:00

53 lines
2.7 KiB
YAML

name: Demos
on:
push:
branches:
- master
pull_request:
branches:
- master
permissions:
contents: read
jobs:
demos:
name: Demos (${{ matrix.shard }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v5
- uses: "./.github/actions/install-and-build"
# Microsoft's Open XML SDK validator. It's installed only here, as it is 80 MB
- name: Install the Open XML SDK validator
run: npm install --no-save --no-audit --no-fund @xarsh/ooxml-validator@0.3.0
# Each shard runs every fourth demo, and checks the document it writes, a .docx or, with macros, a .docm, with the
# Open XML SDK validator, which checks every part against Office's schemas, including Word 2010's extensions.
# It's checked as each version of Office since 2010 reads it: older versions skip the newer extensions and read
# their fallbacks. Office 2007 is left out, as it only knows the standard's first edition, from before ISO/IEC
# 29500, and rejects what Word itself writes.
# The validator checks only the first file it's given (each demo writes one), and its option is
# --officeVersion, not the --office-version its README gives. It reads a version it doesn't know as Microsoft365.
# It doesn't look inside the workbooks that charts embed, so each is checked on its own. unzip exits with 11
# when a document has none
- name: Run and validate the demos
shell: bash
run: |
for demo in $(find demo -mindepth 2 -name "*.ts" -not -path "demo/assets/*" | sort | awk -v n=${{ strategy.job-total }} -v i=${{ strategy.job-index }} 'NR % n == i'); do
echo "::group::$demo"
rm -rf ./*.doc[xm] embeddings
npm run --silent run-ts -- "$demo"
unzip -q ./*.doc[xm] "word/embeddings/*.xlsx" -d embeddings || [ $? -eq 11 ]
for version in Office2010 Office2013 Office2016 Office2019 Office2021 Microsoft365; do
echo "$version"
npx ooxml-validator ./*.doc[xm] --officeVersion "$version"
for workbook in $(find embeddings -name "*.xlsx" 2>/dev/null); do
npx ooxml-validator "$workbook" --officeVersion "$version"
done
done
echo "::endgroup::"
done