include/vbahelper/vbaeventshelperbase.hxx | 2 ++ sc/source/ui/vba/vbaeventshelper.cxx | 5 +++-- vbahelper/source/vbahelper/vbaeventshelperbase.cxx | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-)
New commits: commit 6834fda784f3066a89838cd6cda4fe945f4c7904 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Thu Oct 6 20:00:07 2022 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Fri Oct 7 23:48:36 2022 +0200 related tdf#148806 xls/x vba: no auto_open if Auto_Open module The presence of an Auto_Close module prevents any auto_close subroutines from running. Interestingly, Word is different. It doesn't care at all if such a module is present. (In fact, it uses that module's main() as an AutoClose if there is no Sub AutoClose.) Change-Id: I83a80b7f016dcf2ad3b7fd931acacb6f788241a1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141036 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/include/vbahelper/vbaeventshelperbase.hxx b/include/vbahelper/vbaeventshelperbase.hxx index 0126db442ee8..e7038da7ab75 100644 --- a/include/vbahelper/vbaeventshelperbase.hxx +++ b/include/vbahelper/vbaeventshelperbase.hxx @@ -78,6 +78,8 @@ public: // little helpers --------------------------------------------------------- + bool hasModule(const OUString& rModuleName); + /** Helper to execute event handlers without throwing any exceptions. */ void processVbaEventNoThrow( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ); diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx index bd00fdcac3bd..d412af36b466 100644 --- a/sc/source/ui/vba/vbaeventshelper.cxx +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -659,7 +659,8 @@ bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, rEventQueue.emplace_back(WORKBOOK_ACTIVATE ); uno::Sequence< uno::Any > aArgs{ uno::Any(mxModel->getCurrentController()) }; rEventQueue.emplace_back( WORKBOOK_WINDOWACTIVATE, aArgs ); - rEventQueue.emplace_back(AUTO_OPEN ); + if (!hasModule("Auto_Open")) + rEventQueue.emplace_back(AUTO_OPEN ); // remember initial selection maOldSelection <<= mxModel->getCurrentSelection(); } @@ -779,7 +780,7 @@ void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, case WORKBOOK_BEFORECLOSE: /* Execute Auto_Close only if not cancelled by event handler, but before UI asks user whether to cancel closing the document. */ - if( !bCancel ) + if (!bCancel && !hasModule("Auto_Close")) rEventQueue.emplace_back(AUTO_CLOSE ); break; } diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx index 1f92e449a156..dbd345c9bac7 100644 --- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx +++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx @@ -320,6 +320,23 @@ void VbaEventsHelperBase::ensureVBALibrary() } } +bool VbaEventsHelperBase::hasModule(const OUString& rModuleName) +{ + if (rModuleName.isEmpty()) + return false; + + bool bRet = false; + try + { + ensureVBALibrary(); + bRet = mxModuleInfos->hasModuleInfo(rModuleName); + } + catch (uno::Exception&) + {} + + return bRet; +} + sal_Int32 VbaEventsHelperBase::getModuleType( const OUString& rModuleName ) { // make sure the VBA library exists