[Solved] Closing OpenOffice by macro
[Solved] Closing OpenOffice by macro
Hi,
May I close OpenOffice 3.1 (or LibreOffice 4.1) using a macro assigned to a button on a form?
I read several threads but till now my tries failed and soffice.bin didn't stopped.
Thank you in advance
Marco
May I close OpenOffice 3.1 (or LibreOffice 4.1) using a macro assigned to a button on a form?
I read several threads but till now my tries failed and soffice.bin didn't stopped.
Thank you in advance
Marco
Last edited by Hagar Delest on Sat Nov 01, 2014 11:47 am, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
Apache OpenOffice 4.1.0 - Windows 7
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Closing OpenOffice by macro
Thank you kingfisher,
I tried it but executing oDoc.close(True), I received the error message "Exception: com.sun.star.util.CloseVetoException".
So I tried first to close the main form "Menu" using ThisDatabaseDocument.FormDocuments.getByName("Menu").close
Here is the code:
but I read another error message "variable not defined" and soffice.exe and soffice.bin still hang up.
I tried it but executing oDoc.close(True), I received the error message "Exception: com.sun.star.util.CloseVetoException".
So I tried first to close the main form "Menu" using ThisDatabaseDocument.FormDocuments.getByName("Menu").close
Here is the code:
Code: Select all
Sub CloseDatabase2
Dim oEnum
Dim oDoc
ThisDatabaseDocument.FormDocuments.getByName("Menu").close
oEnum = StarDesktop.getComponents().createEnumeration()
Do While oEnum.hasMoreElements()
oDoc = oEnum.nextElement()
If HasUnoInterfaces(oDoc, "com.sun.star.util.XCloseable") Then
oDoc.setModified(False)
oDoc.close(True)
Else
oDoc.dispose()
End If
Loop
StarDesktop.Terminate()
End Sub
Apache OpenOffice 4.1.0 - Windows 7
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Closing OpenOffice by macro
That's my lot, sorry. The code still works for me.
Apache OpenOffice 4.1.9 on Linux
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Closing OpenOffice by macro
It may help to add the following line before oDoc.close(True) : oDoc.dispose()
EDIT : the code from the other thread closes all files even those which have been modified and not subsequently saved.
EDIT : the code from the other thread closes all files even those which have been modified and not subsequently saved.
Apache OpenOffice 4.1.9 on Linux
-
- Posts: 19
- Joined: Thu Apr 25, 2013 1:08 am
- Location: Arizona, USA
Re: Closing OpenOffice by macro
This is what I use at the end of my backup macro to close out:
Code: Select all
Dim Docs As Object,Components as Object
Components = StarDesktop.getComponents()
Docs = Components.createEnumeration()
Do While Docs.hasMoreElements()
Doc = Docs.nextElement()
Doc.dispose()
loop
Exit Sub
Win 7 - OpenOffice 4.1.1
Re: Closing OpenOffice by macro
Hi kingfisher,
I added oDoc.dispose() before oDoc.close(True) but I received this message:"Type: com.sun.star.lang.DisposedException Message: Component is already disposed".
Thank you for your efforts.
To gkissinger,
thanks for your help; even if I added Dim Doc As object, soffice.bin doesn't terminate.
I added oDoc.dispose() before oDoc.close(True) but I received this message:"Type: com.sun.star.lang.DisposedException Message: Component is already disposed".
Thank you for your efforts.
To gkissinger,
thanks for your help; even if I added Dim Doc As object, soffice.bin doesn't terminate.
Apache OpenOffice 4.1.0 - Windows 7
Re: Closing OpenOffice by macro
Hello
I think you close documents and terminate OpenOffice.
https://www.openoffice.org/api/docs/com ... sktop.html
see also
viewtopic.php?f=20&t=71434&p=320776&hil ... te#p320776
and
viewtopic.php?f=45&t=55266&p=242393&hil ... te#p242393
Romke
I think you close documents and terminate OpenOffice.
https://www.openoffice.org/api/docs/com ... sktop.html
see also
viewtopic.php?f=20&t=71434&p=320776&hil ... te#p320776
and
viewtopic.php?f=45&t=55266&p=242393&hil ... te#p242393
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Closing OpenOffice by macro
One problem is that the close command is returning the 'Exception: com.sun.star.util.CloseVetoException'.
The API page says only :
The API page says only :
this exception can be thrown to prevent the environment of any object from closing
Apache OpenOffice 4.1.9 on Linux
Re: Closing OpenOffice by macro
Hello
viewtopic.php?f=20&t=49434&hilit=terminate
I think in short you can read in the link: You can not close/ terminate Openoffice when:
a) The macro is stored in your document
b) BASIC is running
c) There is an open Dialog then BASIC is running
d) When the IDE is open.
Romke
viewtopic.php?f=20&t=49434&hilit=terminate
I think in short you can read in the link: You can not close/ terminate Openoffice when:
a) The macro is stored in your document
b) BASIC is running
c) There is an open Dialog then BASIC is running
d) When the IDE is open.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Closing OpenOffice by macro
Edit: My posting in error to this thread moved: irrelevant to this topic - RoryOF |
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Closing OpenOffice by macro
Thank you RPG for your clear framework:
While the other 3 conditions (Basic running, open Dialog, open IDE) haven't been present, the macro "CloseDatabase2" was really stored in a document of mine.
So I transferred it in My Macros> Standard>Module1.
Then I run from the button the following code stored in My Macros:
But it stops at oDoc.close(True) and I still receive this; "Type: com.sun.star.util.CloseVetoException"
I'm wondering if there is something I could check in my copy of Open Office.
Furthermore the main directory where Open office is located is owned by me who started the office processes.
You can see, attached, the database I'm testing.
Thank you
While the other 3 conditions (Basic running, open Dialog, open IDE) haven't been present, the macro "CloseDatabase2" was really stored in a document of mine.
So I transferred it in My Macros> Standard>Module1.
Then I run from the button the following code stored in My Macros:
Code: Select all
sub CloseDatabase2
Dim oEnum
Dim oDoc
oEnum = StarDesktop.getComponents().createEnumeration()
Do While oEnum.hasMoreElements()
oDoc = oEnum.nextElement()
If HasUnoInterfaces(oDoc, "com.sun.star.util.XCloseable") Then
oDoc.setModified(False)
oDoc.close(True)
Else
oDoc.dispose()
End If
Loop
StarDesktop.Terminate()
End sub
I'm wondering if there is something I could check in my copy of Open Office.
Furthermore the main directory where Open office is located is owned by me who started the office processes.
You can see, attached, the database I'm testing.
Thank you
- Attachments
-
- Database.odb
- (11.63 KiB) Downloaded 284 times
Apache OpenOffice 4.1.0 - Windows 7
Re: Closing OpenOffice by macro
You can write a program starter in some "real" programming language that starts up the office suite in listening mode, connects to the listening office, plays games with the same UNO-Api as macros do and finally takes care of proper shutdown.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Closing OpenOffice by macro
Hello
I have no solution. Once I have tried it and I did not find a solution. I think when you need to terminate OOo then most easy is: Control-Q or closing all documents by hand. The idea of Villeroy can also be a good idea but is outside my knowledge.
Romke
I have no solution. Once I have tried it and I did not find a solution. I think when you need to terminate OOo then most easy is: Control-Q or closing all documents by hand. The idea of Villeroy can also be a good idea but is outside my knowledge.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Closing OpenOffice by macro
FWIW, this is the wiki developers' page : Closing Documents.
Apache OpenOffice 4.1.9 on Linux
Re: Closing OpenOffice by macro
thanks to everybody.
I'm sure I'm not able to manage Villeroy's suggestion.
Anyway, I found out here: http://www.oooforum.org/forum/viewtopic ... b&start=15
a solution that works for the attached database.
Here is the code:
I'm not able to assess how good the code is and if I could use it in a much more complex database (maybe I couldn't).
Marco
I'm sure I'm not able to manage Villeroy's suggestion.
Anyway, I found out here: http://www.oooforum.org/forum/viewtopic ... b&start=15
a solution that works for the attached database.
Here is the code:
Code: Select all
sub CloseDatabase2 (oEv as object)
' macro assigned to a button on a form to close openoffice
Dim oSvc as object
msgbox " Closing OpenOffice" & chr$(10) & " Goodbye......", 0, " --WARNING-- "
oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
ThisDatabaseDocument.close(true) ' >> close the internal file first
' pass the required parameters to execute a clean shutdown of soffice.exe
wait 2000
oSvc.execute("c:\windows\system32\taskkill.exe", " /F /IM soffice.exe /T" , 0) ' >> windows vista/7 syntax
End Sub
Marco
- Attachments
-
- Database2.odb
- (11.97 KiB) Downloaded 283 times
Apache OpenOffice 4.1.0 - Windows 7
- Greengiant224
- Posts: 283
- Joined: Wed Jun 09, 2010 3:50 pm
- Location: All Over The World
Re: [Solved] Closing OpenOffice by macro
As you will see from the macro you need to close the db file before you shutdown the AOO program.marco:
thanks to everybody.
I'm sure I'm not able to manage Villeroy's suggestion.
Anyway, I found out here: http://www.oooforum.org/forum/viewtopic ... b&start=15
a solution that works for the attached database.
Here is the code:
Code: Select all Expand view
sub CloseDatabase2 (oEv as object)
' macro assigned to a button on a form to close openoffice
Dim oSvc as object
msgbox " Closing OpenOffice" & chr$(10) & " Goodbye......", 0, " --WARNING-- "
oSvc = createUnoService("com.sun.star.system.SystemShellExecute")
ThisDatabaseDocument.close(true) ' >> close the internal file first
' pass the required parameters to execute a clean shutdown of soffice.exe
wait 2000
oSvc.execute("c:\windows\system32\taskkill.exe", " /F /IM soffice.exe /T" , 0) ' >> windows vista/7 syntax
End Sub
Failure to do this would result in data corruption especially, if you have been inserting/updating data.
I have been using this macro with a button on some of my db's without any detriment for three years.
You can store the macro in the db document or in the standard macro library, the choice is entirely yours.
Glad you got the code to work on your database.
Greengiant224
Win 7, Portable AOO 4.1.14, LibreOffice 6.2, 7.4.5 & 7.6.1 (Java 1.7.81 & 1.8.0_281) utilising HSQL 1.8.10 & 2.4.*, MySQL, PostgreSQL, SQLite
+ Blood, Sweat and Tears (Application, Determination and Perseverance)