diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f549aec2b..ba54404ab 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -826,8 +826,15 @@ impl SheetApp { } let vba: Vec<&str> = msgs.iter().copied().filter(|m| m.to_lowercase().contains("macro") || m.contains("VBA")).collect(); if !vba.is_empty() { + // The reader says "dropped" when the VBA project was missing or unreadable; never promise to keep it then. + let dropped = vba.iter().any(|m| m.contains("dropped")); + let text = if dropped { + "This workbook's VBA macros could not be loaded and were dropped, so they will not be in the saved file. Keep the original file." + } else { + "This workbook contains VBA macros. GridCraft keeps them when you save as .xlsm, but does not run them." + }; self.notice = Some(Notice { - text: "This workbook contains VBA macros. GridCraft keeps them intact when you save, but does not run them.".into(), + text: text.into(), kind: NoticeKind::Warning, action: Some(("What this means".into(), "macros".into())), }); diff --git a/crates/ui-egui/tests/interaction.rs b/crates/ui-egui/tests/interaction.rs index 02084ffb8..0b1d5c42e 100644 --- a/crates/ui-egui/tests/interaction.rs +++ b/crates/ui-egui/tests/interaction.rs @@ -781,6 +781,22 @@ fn opening_a_macro_workbook_shows_a_notice() { assert!(h.state().notice.is_none()); } +#[test] +fn dropped_macro_warning_never_promises_to_keep_macros() { + let mut h = harness(blank()); + for w in [ + "macros (VBA project) reference a missing part and were dropped", + "macros (VBA project) could not be read and were dropped: bad zip", + ] { + h.state_mut().show_open_warnings(&json!({"warnings": [w]})); + let n = h.state().notice.clone().unwrap(); + assert_eq!(n.kind, gridcraft_ui_egui::NoticeKind::Warning); + assert!(n.text.contains("dropped") && !n.text.contains("keeps them"), "{}", n.text); + } + h.state_mut().show_open_warnings(&json!({"warnings": ["macros (VBA project) were kept but not executed"]})); + assert!(h.state().notice.clone().unwrap().text.contains("keeps them when you save as .xlsm")); +} + #[test] fn plain_open_warning_becomes_an_info_notice() { let mut h = harness(blank());