From e2abb5bbc03cca884fa89345003d013688f0d94d Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Fri, 7 Oct 2022 19:35:59 -0400 Subject: [PATCH] tdf#148806 doc vba: accept module AutoOpen.Main This is the lowest priority way of running AutoOpen, and it only applies to Word, not Excel. There is some code in basic/source/classes/sb.cxx that was somewhat finding this before it got lost in LO 7.4 with commit beb6c62e990599d91ac5d9183164c94d269027d3. TODO: these AutoOpens should only run with a public sub, not a private one. Change-Id: I8a733cde13f96636942d84a0b05520692aac3e52 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141094 Tested-by: Jenkins Reviewed-by: Justin Luth --- .../source/vbahelper/vbaeventshelperbase.cxx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx index dbd345c9bac7..cbe8ca79bad7 100644 --- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx +++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -367,7 +368,22 @@ VbaEventsHelperBase::ModulePathMap& VbaEventsHelperBase::updateModulePathMap( co { const EventHandlerInfo& rInfo = rEventInfo.second; if( rInfo.mnModuleType == nModuleType ) - rPathMap[ rInfo.mnEventId ] = resolveVBAMacro( mpShell, maLibraryName, rModuleName, rInfo.maMacroName ); + { + OUString sName = resolveVBAMacro(mpShell, maLibraryName, rModuleName, + rInfo.maMacroName); + // Only in Word (with lowest priority), an Auto* module can execute a "Public Sub Main" + if (sName.isEmpty() && rModuleName.isEmpty() + && getImplementationName() == "SwVbaEventsHelper") + { + if (rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_NEW + || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_OPEN + || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_CLOSE) + { + sName = resolveVBAMacro(mpShell, maLibraryName, rInfo.maMacroName, "Main"); + } + } + rPathMap[rInfo.mnEventId] = sName; + } } return rPathMap; }