Close from macro and norestore

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
OLDFOX
Posts: 2
Joined: Fri Nov 23, 2018 6:37 pm

Close from macro and norestore

Post by OLDFOX »

I made a quite complex Basic macro in Calc that, at the end of its work, closes all temporary sheets it created, saves all documents (with appropriate .store instructions) and finally closes OpenOffice completely by using StarDesktop.Terminate.
The macro works well and documents are correctly saved, but at the next start of Calc, invariably the "document restore" window appears with the name of the spreadsheet where the macro was included. In fact there is nothing to restore and the spreadsheet gets restored anyway, but I do not want to force my user to always see the restore window and to click two times to confirm. But, if I try to start Calc with the "-norestore" option, the restore window appears anyway.
So I can solve my problem in two ways:
- Close the macro cleanly, so that there is no need to restore the document. But what can I do, besides using store and terminate? I understand that the problem is due to the macro closing itself.
- Open next time with a working norestore option, but this does not work (i am on Windows 10, with OpenOffice 4.1.5).
Some advices? Thank you!
OpenOffice 4.1.5 on Windows 10
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Close from macro and norestore

Post by RoryOF »

Sometimes code needs delay loops inserted to permit actions complete before subsequent commands are executed.

I have a memory that this problem came up before and I doubt any solution was found: consider this - the macro closes the file (itself). Then where does it return to for its next instruction, even if that is only an "end sub"?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Close from macro and norestore

Post by FJCC »

Just a guess - what if you store the macro in My Macros so you can close the document cleanly and then terminate OpenOffice?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Close from macro and norestore

Post by Lupp »

The StarDesktop.Terminate method cannot be executed from a document macro. That this results in the recovery issue is bad. The command should be rejected.

An application macro can do it if no veto is thrown by any listener. I just tested this in AOO 4.1.5 and in LibO 6.1.3 with the StartDesktop.Terminate in the last line of the macro. Of course you are back to your issue if you call that application macro from a document macro.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
OLDFOX
Posts: 2
Joined: Fri Nov 23, 2018 6:37 pm

Re: Close from macro and norestore

Post by OLDFOX »

I think it will not be possible for me to usa an application macro instead of a document macro.
But I could have a working solution if the online option -norestore were working on next start of Calc. Is i just not working in this version, or for all Windows versions at all?
OpenOffice 4.1.5 on Windows 10
Post Reply