Skip to content

Preserve VBA macros + Excel-style macros UX (issue #6) - #19

Merged
h-a-n-a-s-h-i merged 5 commits into
storytold:mainfrom
justinjohn0306:fix/vba-macro-preservation
Oct 11, 2026
Merged

h-a-n-a-s-h-i merged 5 commits into
storytold:mainfrom
justinjohn0306:fix/vba-macro-preservation

Conversation

@justinjohn0306

@justinjohn0306 justinjohn0306 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Opening a macro-enabled workbook (.xlsm) and saving it silently stripped xl/vbaProject.bin, turning it into a macro-free file. For anyone whose work depends on macros, that is data loss — the same class of failure as a crash, which this project ranks above feature work.

GridCraft still does not run VBA (its own recorded/editable scripts remain the automation path). It now carries the project through unchanged, so a macro-enabled workbook survives open → edit → save, and the UI tells the user so in an Excel-shaped surface rather than dropping the warning on the floor.

Changes

Engine — preserve, don't destroy

  • model — Workbook.vba_project: Option<Vec<u8>> (base64 in JSON via a new b64::opt helper). None = no macros.
  • xlsx read — capture the vbaProject relationship's bytes instead of warning and dropping them; warn that macros are kept but not executed.
  • xlsx write — when present, emit xl/vbaProject.bin byte-identical, add the .../relationships/vbaProject relationship, switch the main part to the macro-enabled content type (...sheet.macroEnabled.main+xml), and add the application/vnd.ms-office.vbaProject override.
  • engine — view.macros lists the preserved project alongside GridCraft's own scripts ({"kind":"vba","executed":false}).
  • ROADMAP — scope changed from "out of scope" to "preserve, don't execute" (per @echelon).

UI — Excel-style surfaces, honest about what GridCraft does (the open-time warning used to be discarded)

  • Info bar under the ribbon (Excel's message-bar slot). A VBA project gets an amber bar: "This workbook contains VBA macros. GridCraft keeps them intact when you save, but does not run them." with a What this means button; any other open-time warning becomes a blue informational bar. Dismissable, and a clean open clears a stale notice.
  • Macros dialog (Automate ▸ Macros, Alt+F8) — lists GridCraft's own scripts and the preserved VBA project (presence, not module names: the blob is opaque without a CFB/OLE2 parse). Mirrors Excel's Developer ▸ Macros without a false "Enable Content".
  • Status-bar badge — "Macros preserved (not executed)" whenever the workbook carries a VBA project.
  • Follows light/dark via new theme tokens; reachable from the control channel via ui.notice / ui.notice.dismiss.

Tests

  • Round-trip: blob survives byte-identical; content types + relationship are correct; a macro-free workbook stays clean.
  • Capture from a foreign-produced .xlsm (not our own writer).
  • UI: info bar appears for a macro workbook and clears on dismiss; a non-VBA warning becomes an info bar; a clean open clears the notice; the macros dialog lists the VBA entry; the status bar renders with a VBA project; Alt+F8 opens the dialog.
  • Snapshot-verified (light + dark) and end-to-end via scripts/check-vba-roundtrip.sh.

Notes

  • This branch also carries a separate, first commit of behavior-preserving clippy fixes for pre-existing toolchain drift (local clippy 1.96 vs. the tree). These lints fire on clean main and block cargo xtask ci; they are unrelated to VBA and split out so they can be reviewed/dropped independently. Repro: git stash + clippy on pristine main.
  • No VBA interpreter is proposed here. That is a separate, much larger milestone and was not requested. A real macro-name list (Excel's Alt+F8) would need CFB/OLE2 parsing of vbaProject.bin; this PR shows presence + size only.

Closes #6.

Local clippy (1.96) flags pre-existing code that an older toolchain accepted;
these lints fire on clean main and block `cargo xtask ci`. All rewrites are
behavior-preserving:

- core/date.rs, numfmt/render.rs, functions/math.rs, functions/stat.rs:
  `!x.is_finite() || x < a || x >= b` -> `!(a..b).contains(&x)` (Range::contains
  is false for NaN/inf, matching the existing is_finite guard).
- functions/util.rs: `!(A && !B)` -> `!A || B`.
- engine/cmd/file.rs: drop a dead `.filter(|| true)`.
- ui-egui/grid.rs: `find(|| true)` was always the first table (use `.first()`);
  `wrap || Justify || (nl && wrap)` -> `wrap || Justify`.
- ui-egui/formula_bar.rs: `tab || (enter && false)` -> `tab`.
- engine/cmd/spelling.rs: split the wasm/non-wasm dictionary init so the
  non-wasm `mut` no longer warns under wasm check.
…book (storytold#6)

Opening an .xlsm and saving it silently stripped xl/vbaProject.bin, turning a
macro-enabled workbook into a macro-free one — data loss for anyone whose work
depends on macros. GridCraft still does not run VBA, but it now carries the
project through unchanged.

- model: `Workbook.vba_project: Option<Vec<u8>>` (base64 in JSON via a new
  `b64::opt` helper). `None` = no macros.
- xlsx read: capture the `vbaProject` relationship's bytes instead of warning
  and dropping them; warn that macros are kept but not executed.
- xlsx write: when present, emit `xl/vbaProject.bin` byte-identical, add the
  `.../relationships/vbaProject` relationship, switch the main part to the
  macro-enabled content type (`...sheet.macroEnabled.main+xml`) and add the
  `application/vnd.ms-office.vbaProject` override.
- engine: `view.macros` lists the preserved project alongside GridCraft's own
  scripts (`{"kind":"vba","executed":false}`), so callers can see it is there.
- ROADMAP: scope now "preserve, don't execute" (was "out of scope").

Tests: round-trip byte-identical blob + correct content types/relationship;
capture from a foreign-produced .xlsm; a macro-free workbook stays clean.
… file

Builds a macro-enabled .xlsm with a fake xl/vbaProject.bin, runs it through
`gridcraft-cli run`, and asserts the blob comes back byte-identical with the
macro-enabled content type and vbaProject relationship intact — the
open → edit → save path a user would exercise by hand.
…torytold#6)

The engine now preserves a workbook's VBA project, but the UI had no surface
for it and silently dropped every open-time warning. Give preserved macros an
honest, Excel-shaped home without a false "Enable Content":

- Info bar under the ribbon (Excel's message-bar slot) showing the warning a
  `file.open` result carries. A VBA project gets an amber bar reading "This
  workbook contains VBA macros. GridCraft keeps them intact when you save, but
  does not run them." with a "What this means" button; anything else becomes a
  blue informational bar. Dismissable; a clean open clears a stale notice.
- Macros dialog (Automate ▸ Macros, Alt+F8): lists GridCraft's own scripts and
  the preserved VBA project (presence + size, not module names — the blob is
  opaque). Mirrors Excel's Developer ▸ Macros without claiming to run VBA.
- Status-bar badge "Macros preserved (not executed)" whenever the workbook
  carries a VBA project.

New panel `notice_bar` reuses theme tokens (notice_warn_*/notice_info_*), so it
follows light/dark. Two new UI commands, `ui.notice` and `ui.notice.dismiss`,
reach it from the control channel.

Tests: info bar appears for a macro workbook and clears on dismiss; a non-VBA
warning becomes an info bar; clean open clears the notice; the macros dialog
lists the VBA entry; status bar renders with a VBA project; Alt+F8 opens the
dialog. Snapshot-verified in light and dark.
@justinjohn0306 justinjohn0306 changed the title Preserve VBA macros on round-trip (issue #6) Preserve VBA macros + Excel-style macros UX (issue #6) Oct 8, 2026
@echelon

echelon commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thank you — and good to see GridCraft never executes VBA here (opaque bytes, honest UX wording). Needed before merge: (1) saving as .xlsx with vba_project set writes a macro-enabled package that Excel refuses — drop the project with a warning (or steer to .xlsm) when the target isn't xlsm/xltm; (2) the warning bar decides "macros kept" by matching warning text, so it can claim macros were kept when they were dropped — decide from wb.vba_project.is_some(); (3) please drop scripts/check-vba-roundtrip.sh (embedded Python; the repo is Rust-only and the Rust round-trip test covers it); (4) split the unrelated clippy-drift changes out (most already landed via other PRs, so a rebase should shrink them). Nice-to-have: route Alt+F8/the ribbon button through a command that returns UiRequest::Dialog; note that vbaProjectSignature.bin isn't preserved (signed macros come back unsigned).

If you haven't already, please come join us on Discord: https://discord.gg/artcraft — happy to talk any of this through there.

…sx never carries a VBA project); drop the shell round-trip script (review fix-up for storytold#19)

The Rust round-trip test covers what scripts/check-vba-roundtrip.sh checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit fb3737a into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Merged — thank you for the contribution! (I merged main into your branch and made one behaviour change: macros are saved only into an .xlsm — saving under an .xlsx name writes the workbook without the VBA project, as Excel does, since Excel refuses an .xlsx with a macro-enabled main part. I also dropped scripts/check-vba-roundtrip.sh, since your Rust round-trip test covers it.)

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VBA Macros support

3 participants