From eaa38b0f9d672793af500222348a6cacd28910b0 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Sat, 8 Oct 2022 09:07:53 -0400 Subject: tdf#148806 doc vba: only autoOpen PUBLIC macros Note: this should NOT apply to Document_Open which normally is a private subroutine and runs fine as private. I tested and it DOES apply to all three version of AutoOpen: -ThisDocument.AutoOpen, -.AutoOpen, -AutoOpen.Main Note: this is different from Excel. Private Auto_Open runs just fine there. Change-Id: If10c8c90c35275c2b14dc2e15fb357674fc580b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141114 Tested-by: Justin Luth Reviewed-by: Justin Luth --- vbahelper/source/vbahelper/vbaeventshelperbase.cxx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'vbahelper') diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx index cbe8ca79bad7..e9bd0f476f40 100644 --- a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx +++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx @@ -369,8 +369,18 @@ VbaEventsHelperBase::ModulePathMap& VbaEventsHelperBase::updateModulePathMap( co const EventHandlerInfo& rInfo = rEventInfo.second; if( rInfo.mnModuleType == nModuleType ) { + // Only in Word, Auto* only runs if defined as Public, not Private. + const bool bOnlyPublic + = getImplementationName() == "SwVbaEventsHelper" + && (rInfo.mnEventId == css::script::vba::VBAEventId::DOCUMENT_AUTO_NEW + || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_NEW + || rInfo.mnEventId == css::script::vba::VBAEventId::DOCUMENT_AUTO_OPEN + || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_OPEN + || rInfo.mnEventId == css::script::vba::VBAEventId::DOCUMENT_AUTO_CLOSE + || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_CLOSE); + OUString sName = resolveVBAMacro(mpShell, maLibraryName, rModuleName, - rInfo.maMacroName); + rInfo.maMacroName, bOnlyPublic); // Only in Word (with lowest priority), an Auto* module can execute a "Public Sub Main" if (sName.isEmpty() && rModuleName.isEmpty() && getImplementationName() == "SwVbaEventsHelper") @@ -379,7 +389,8 @@ VbaEventsHelperBase::ModulePathMap& VbaEventsHelperBase::updateModulePathMap( co || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_OPEN || rInfo.mnEventId == css::script::vba::VBAEventId::AUTO_CLOSE) { - sName = resolveVBAMacro(mpShell, maLibraryName, rInfo.maMacroName, "Main"); + sName = resolveVBAMacro(mpShell, maLibraryName, rInfo.maMacroName, "Main", + bOnlyPublic); } } rPathMap[rInfo.mnEventId] = sName; -- cgit