Bug 148806 - FILEOPEN: Event-Driven Macros don't enable in DOCM, or after round-tripping in DOC
Summary: FILEOPEN: Event-Driven Macros don't enable in DOCM, or after round-tripping i...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: UI (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard: target:7.5.0 inReleaseNotes:7.5
Keywords: filter:docx
: 147159 (view as bug list)
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2022-04-26 16:26 UTC by siti
Modified: 2023-05-08 11:32 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Assign evant macros (85.18 KB, image/png)
2022-04-27 05:50 UTC, siti
Details
save and close doc (64.47 KB, image/png)
2022-04-27 05:50 UTC, siti
Details
Reopened doc (62.92 KB, image/png)
2022-04-27 05:51 UTC, siti
Details
formfieldMacros.docm: macro on fileOpen, checkbox1 click (25.93 KB, application/vnd.ms-word.document.macroEnabled.12)
2022-09-26 18:40 UTC, Justin L
Details
autoOpenClose.dot: manual testing document (41.50 KB, application/msword-template)
2022-10-12 16:10 UTC, Justin L
Details
autoOpenClose.xls: Excel VBA is completely different from Word (31.00 KB, application/vnd.ms-excel)
2022-10-12 16:39 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description siti 2022-04-26 16:26:46 UTC
Description:
When I assign a Event-Driven Macros and it is saved in the current document, there is no assignment of the macro to the event after reopening that document.

Steps to Reproduce:
1.Make macros
2. Assing it to Event-Driven Macros
3.Save and Close document
4. Reopen document

Actual Results:
No saved Event-Driven Macros in reopened document

Expected Results:
Event-Driven Macros in reopened document sould be present


Reproducible: Always


User Profile Reset: No



Additional Info:
no
Comment 1 siti 2022-04-26 16:27:56 UTC Comment hidden (obsolete)
Comment 2 Timur 2022-04-26 19:20:59 UTC
*** Bug 147159 has been marked as a duplicate of this bug. ***
Comment 3 Timur 2022-04-26 19:25:58 UTC Comment hidden (obsolete)
Comment 4 siti 2022-04-27 05:50:01 UTC
Created attachment 179797 [details]
Assign evant macros
Comment 5 siti 2022-04-27 05:50:59 UTC
Created attachment 179798 [details]
save and close doc
Comment 6 siti 2022-04-27 05:51:28 UTC
Created attachment 179799 [details]
Reopened doc
Comment 7 siti 2022-04-27 05:57:14 UTC
(In reply to Timur from comment #3)
> You assign a macro to some event? Did you try with different events? 
Yes. I tried other one. 


> User Profile Reset: indicates you should try to rename LO user profile. You
> need to save macros separately.

Не совсем понял что и как надо сделать.
Comment 8 Timur 2022-04-27 08:23:58 UTC
I confirm with Lo 7.4+ that event-driven macro saves in ODT or ODS but not in Micorsoft formats, tested XLS, XLSX, DOC, DOCX. 

But it's a duplicate.

*** This bug has been marked as a duplicate of bug 107960 ***
Comment 9 Timur 2022-04-27 08:26:28 UTC Comment hidden (obsolete)
Comment 10 siti 2022-04-27 08:57:28 UTC
(In reply to Timur from comment #9)
> Can be a duplicate of bug 107960 but let's keep separate so far.

It is looks like not the same bug.
Comment 11 Justin L 2022-09-26 18:40:29 UTC
Created attachment 182687 [details]
formfieldMacros.docm: macro on fileOpen, checkbox1 click

repro 7.5+
This is a FILEOPEN problem. Round-tripping this file still works fine in Excel.

DOC format is a bit better than this. At least on initial file-open the checkbox1 and commandButton macros are working. LO doesn't work on a RT though.

DOCX format has never worked in LO. ActiveX support first came in LO 6.0 via bug 50097, but event-macros were never working.
Comment 12 Commit Notification 2022-09-29 22:11:46 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/8253b8d6f1efb7fc3e2928d543c21a79c2cdc13f

tdf#148806 docm: fix vba macro events without ScriptCodes

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Justin L 2022-09-29 23:06:52 UTC
DOCX: in terms of sending DOCUMENT OPEN to VBA, all the plumbing looks to be in place. The only problem is an exception in 
mxVbaEvents.set( ooo::vba::createVBAUnoAPIServiceWithArgs(
   mpDocShell, "com.sun.star.script.vba.VBATextEventProcessor" , aArgs )
because no hasServiceName("com.sun.star.script.vba.VBATextEventProcessor")

Somehow we need this?
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
Writer_SwVbaEventsHelper_get_implementation(
    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
{
    return cppu::acquire(new SwVbaEventsHelper(args, context));
}
Comment 14 Justin L 2022-09-30 20:36:18 UTC
A proposed patch for exposing document open/close/new to VBA macros is at http://gerrit.libreoffice.org/c/core/+/140801

DOC round-trip losing macros:
I just want to confirm that MS Word handled the round-tripped file just fine.
In LO, it fails at forms/source/misc/InterfaceContainer.cxx:119
Reference< XModel > xDoc( getXModel( static_cast< XContainer *> ( this ) ) );
if ( !xDoc.is() )
    break;  // ROUND-TRIPPED file hits this.
Comment 15 Justin L 2022-10-01 02:16:46 UTC
> DOC round-trip losing macros:
This never worked for the checkboxes. ActiveX checkboxes were round-tripped as FormField's until LO 6.0's commit b45446fcb4958b13bc94e70e2d3d1940db3322e2
Author: Tamás Zolnai on Tue Aug 22 23:40:56 2017 +0200
    tdf#111975: Inline checkbox control's label is not saved to DOC format
    
    This MiserableFormFieldExportHack lives from the beginning
    of the git history:
    7155b11b7eac65e242aca1efaf29ffcfa28f2564
    
    So it might be a workaround of an old issue. By now when
    the checkbox is not inline, but a floating one, it is exported
    as ActiveX control, which works nicely. So just remove this
    workaround and let the code export also inline checkboxes
    as ActiveX controls.

Did it ever work for the button? On import, the macro got wired back up in LO 5.2 with commit 1f7a31a461bb3a6fcd277ab57875405875568f8b
Author: Stephan Bergmann on Tue May 10 10:08:35 2016 +0200
    Missing break in switch

which was broken 5 years earlier with
commit 4fae740db79d4e7cc97440e2bab8d1ef612d9b51
Author: Noel Power on Fri Aug 12 00:36:51 2011 -0400
    Disable fake VBA events for the old-style form controls.
Comment 16 Commit Notification 2022-10-01 06:56:35 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/acc71c3e502f23daaf2489d102dda3b00a45960a

tdf#148806 sw vba: fix GetVbaEventProcessor

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Justin L 2022-10-03 20:56:45 UTC
(In reply to Justin L from comment #14)
> In LO, it fails at forms/source/misc/InterfaceContainer.cxx:119
In the working case, we have parents
uno::Reference to (frm::ODatabaseForm *)
uno::Reference to (frm::OFormsCollection *)  // ends here on RT import
uno::Reference to (SwXTextDocument *)
Comment 18 Commit Notification 2022-10-05 15:39:38 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d02962cb2ca4e691634abb1bf6ff30b9b366d2e3

tdf#148806 doc import: remove 2003 SetObjectShell(nullptr) hack

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 19 Justin L 2022-10-06 17:28:06 UTC
There is another way that can auto-execute a macro in Word - if a module AutoOpen exists with a PUBLIC SUB MAIN. (PRIVATE doesn't work, FUNCTION doesn't work, any other name than MAIN doesn't work, and it doesn't work if a sub AutoOpen exists)

This is different from Excel's auto_open (which is already mostly working in LO) which has no such thing with special modules AFAICS.

Some current Calc differences:
-In LO, we have first-come, first-served when multiple auto_open subroutines defined. In Excel it gives error "Ambiguous name detected: auto_open" (but note that in Word it is also first come, first served).
-in both LO and Excel, auto_open() in ThisWorkbook is ignored. It doesn't run or cause a conflict (but note that in Word it does run and has priority)
-in Excel, if an Auto_Open module exists, it PREVENTS "sub auto_open" from running (but note that in Word it just overrides AutoOpen.main).
Comment 20 Commit Notification 2022-10-07 21:49:01 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6834fda784f3066a89838cd6cda4fe945f4c7904

related tdf#148806 xls/x vba: no auto_open if Auto_Open module

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 21 Commit Notification 2022-10-08 10:08:42 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/21c0b368a3e7150fc5d18af5d568d5683a7a6a3a

tdf#148806 doc vba: AutoOpen runs before Document_Open

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 22 Commit Notification 2022-10-08 14:14:39 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/3d77fe0af515830001448fde0d394ef20a89002b

tdf#148806 doc vba: highest priority is ThisDocument AutoOpen

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 23 Commit Notification 2022-10-08 23:08:11 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/e2abb5bbc03cca884fa89345003d013688f0d94d

tdf#148806 doc vba: accept module AutoOpen.Main

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 24 Commit Notification 2022-10-08 23:11:20 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d72571fdd47c627efcd0dff92fbe8a9747f92932

related tdf#148806 flatten filter/source/msfilter/msvbahelper.cxx

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 25 Commit Notification 2022-10-11 01:08:32 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/eaa38b0f9d672793af500222348a6cacd28910b0

tdf#148806 doc vba: only autoOpen PUBLIC macros

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 26 Commit Notification 2022-10-11 14:44:57 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/195cb01573cbc92545cbc84cbb7dd09bbb4ae692

tdf#148806 fix build for !HAVE_FEATURE_SCRIPTING

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 27 Commit Notification 2022-10-11 18:39:29 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ffc15725b58d0988b4e2ed836c5751223ad00984

tdf#148806 tdf#151393 xls vba: no Auto_Open from ThisWorksheet

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 28 Commit Notification 2022-10-11 23:12:51 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/73911ed8d35294a9e15771d8aaa1e9121ef10309

tdf#148806 doc vba: highest priority is ThisDocument AutoOpen V2

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 29 Justin L 2022-10-11 23:25:08 UTC
Just to be clear - I'm using this bug report to handle opening and round-tripping of MS formats related to new/open/close. That should be fixed now.

For the enhancement of LO being able to modify VBA event-macros, use bug 105813 for that.
Comment 30 Commit Notification 2022-10-12 13:24:56 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1e0306be6c3a3bc50f11e7c7814aa8a029f8928d

tdf#148806 vba: IsCompiled is required for SbxFlagBits::Private

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 31 Justin L 2022-10-12 16:10:09 UTC
Created attachment 183002 [details]
autoOpenClose.dot: manual testing document

LO cannot save changes to VBA Macros, so I used the CLOSE event to design a manual test. The changes made by Tools - Macros - Edit Macros will affect the close - but will not be saved.

Manual testing
-open autoOpenClose.dot:
	-AutoNew SUBROUTINE (from module AutoNew) runs first
              -demonstrates autorun order
	-Document_New runs second – a special ThisDocument event.
-save as .doc or .docm and close:
	-nothing is seen on close (all AutoClose are private)
         and Document_Close is disabled.
-open round-tripped file.
	-AutoOpen.Main adds text, demonstrating AutoOpen MODULE autorun.
	-also demonstrates docm and round-tripping support.
-change VBA - make AutoClose.Main public
	-close: demonstrating Private should not autorun
-change VBA - same as before plus make AutoClose.AutoClose public
	-close: demonstrates that AutoClose subroutine has priority,
         and only one AutoClose runs.
-change VBA - same as before plus make aaaSorting.AutoClose public
	-close: demonstrates first found autorun is the only one activated.
-change VBA - same as before plus change module name to zzzSorting
        -close: again demonstrating first come, first served.
-change VBA - same as before plus make ThisDocument.AutoClose public
	-close: demonstrating ThisDocument priority.

I attempted an automated test at https://gerrit.libreoffice.org/c/core/+/141077, but the TypeText always outputs to the top of the document, which is not correct.
Comment 32 Justin L 2022-10-12 16:39:49 UTC
Created attachment 183003 [details]
autoOpenClose.xls: Excel VBA is completely different from Word

Manual testing
-open autoOpenClose.xls
  -Workbook_Open runs first, Auto_Open runs second
  -close: nothing happens
     -demonstrating that an Auto_Close MODULE prevents autorun
     -demonstrates that an Auto_Close.Main subroutine couldn't work either.
-change VBA: rename module to xxxAuto_Close
  -close: In Excel, compile error because there are multiple Auto_Close subroutines.
      -I didn't handle this case. Just treating like Word - first come, first served.
-change VBA: same as before, plus delete Auto_Close_Duplicate
  -close: this is the only one that works in Excel.
      -demonstrates that PRIVATE Auto_Close SHOULD run.
-change VBA: delete modules Auto_Close and Auto_Close_Duplicate
  -close: nothing happens
      -demonstrates that THISWORKSHEET.Auto_Close subroutine does nothing.