diff --git a/sc/qa/unit/data/ods/vba-document-module.ods b/sc/qa/unit/data/ods/vba-document-module.ods new file mode 100644 index 000000000000..59397a648b9b Binary files /dev/null and b/sc/qa/unit/data/ods/vba-document-module.ods differ diff --git a/sc/qa/unit/subsequent_filters_test.cxx b/sc/qa/unit/subsequent_filters_test.cxx index d9280d1f1ea6..2e777e92aa80 100644 --- a/sc/qa/unit/subsequent_filters_test.cxx +++ b/sc/qa/unit/subsequent_filters_test.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include #include #include @@ -160,6 +161,25 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest, testDrawImageRemoteNotFetched) CPPUNIT_ASSERT(pDoc); } +CPPUNIT_TEST_FIXTURE(ScFiltersTest, testVBADocumentBasicAfterLoad) +{ + // A document in VBA compatibility mode with a VBA document module, loaded with macros not + // allowed, gets its Basic only when something first asks for it. Here that is the INDIRECT + // in A1 compiling "FOO" during a recalculation. Loading the document module asks for the + // document Basic again while the first request is still creating it. + uno::Sequence aParams = { + comphelper::makePropertyValue(u"MacroExecutionMode"_ustr, + css::document::MacroExecMode::NEVER_EXECUTE), + }; + loadFromFile(u"ods/vba-document-module.ods", aParams); + + ScDocShell* pDocSh = getScDocShell(); + pDocSh->DoHardRecalc(); + + CPPUNIT_ASSERT_EQUAL(u"#REF!"_ustr, getScDoc()->GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT(pDocSh->GetBasic()); +} + CPPUNIT_TEST_FIXTURE(ScFiltersTest, testContentODS) { createScDoc("ods/universal-content.ods"); diff --git a/sfx2/source/appl/appbaslib.cxx b/sfx2/source/appl/appbaslib.cxx index 1f8c96bbfe4a..c02066ea6f23 100644 --- a/sfx2/source/appl/appbaslib.cxx +++ b/sfx2/source/appl/appbaslib.cxx @@ -51,6 +51,11 @@ void SfxBasicManagerHolder::Notify(SfxBroadcaster& rBC, SfxHint const& rHint) void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager ) { + // A document's Basic manager can be handed over a second time while it is still being + // created. The holder already listens to it and holds its containers, so it stays as it is. + if ( _pBasicManager == mpBasicManager ) + return; + impl_releaseContainers(); #if !HAVE_FEATURE_SCRIPTING