[Solved] Close OOo from a macro
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
[Solved] Close OOo from a macro
It would be useful to be able to close the whole shebang from a command button, as in VBA 'application.quit' which closes all forms and the main programme returning the user to a pure Windows environment. I cannot find any reference to an equivalent in OO?
Last edited by Hagar Delest on Sun Jun 15, 2014 11:02 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 4 on Windows 7
Re: Close OO from a macro
Hello
I think: stardesktop.terminate
http://www.openoffice.org/api/docs/comm ... sktop.html
Maybe store the macro in myMacros.
See here to the end of the thread.
http://www.oooforum.org/forum/viewtopic ... b&start=15
Romke
I think: stardesktop.terminate
http://www.openoffice.org/api/docs/comm ... sktop.html
Maybe store the macro in myMacros.
See here to the end of the thread.
http://www.oooforum.org/forum/viewtopic ... b&start=15
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Close OO from a macro
This may be of interest also: Automating OpenOffice on Windows and session manager.
Apache OpenOffice 4.1.9 on Linux
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OO from a macro
Having closed all active forms bar the dialog with the 'CLOSE button on it, the 'cose' sub is in mymacros/standard/module1, but 'stardesktop.terminate' drops me into that module IDE and informs me that I cannot 'close' while Basic is running.
KF - I had not thought of running via a script.
KF - I had not thought of running via a script.
OpenOffice 4 on Windows 7
Re: Close OO from a macro
Hello
We cannot see your program but I think you cannot close OOo from a dialog.
Solution close first the dialog and then close OOo
I have not test it.
Romke
We cannot see your program but I think you cannot close OOo from a dialog.
Solution close first the dialog and then close OOo
I have not test it.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OO from a macro
There's the problem. 'Basic' still runs.This is the latest incarnation.Solution close first the dialog and then close OOo
Code: Select all
sub main
DialogLibraries.loadLibrary("Standard")
d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
d.execute()
sub CommandButton1 (Dialog1 as Object)
d.endexecute()
closeprog()
end sub
sub closeprog()
stardesktop.terminate()
End sub
OpenOffice 4 on Windows 7
Re: Close OO from a macro
Hello
I think your code is to much simplified
Try to use one sub less. Why do you use a sub for one line of code.
Romke
I think your code is to much simplified
Try to use one sub less. Why do you use a sub for one line of code.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Close OO from a macro
Hello
I think you must close the sub in an other way.
Make a button. Prepare the button well, this means. The button must close the dialog. Use the properties
I think after this you can close OOo. But I have not test it.
I have no example code.
Romke
I think you must close the sub in an other way.
Make a button. Prepare the button well, this means. The button must close the dialog. Use the properties
- Default button :Yes
State
Button type
I think after this you can close OOo. But I have not test it.
I have no example code.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Close OO from a macro
Hello
I did now test some code. I did see when you want terminate OOo then the IDE must be closed. The next code is working.
s
I don't know a solution for the error I get when I restart OOo. I think we must close first the IDE before terminating.
Romke
I did now test some code. I did see when you want terminate OOo then the IDE must be closed. The next code is working.
s
Code: Select all
ub terminateOOo
oSearchDialog = CreateUnoDialog( DialogLibraries.Hulp.Dialog1 ) ' Dit maak een verbinding naar de dialoog
oSearchDialog.Execute() ' en dit maakt het zicht baar
thiscomponent.store
thiscomponent.close(true)
stardesktop.terminate
end sub
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OO from a macro
Yes, I know, I used to 'mangle' Dutch, but 'Help' gives me method or property not found:Help which is why I asked.
OpenOffice 4 on Windows 7
Re: Close OOo from a macro
Hello
What name I use there is not important only the three lines lower are important. I did test more and I think it is not a good idea to close OOo complete with macros. On this moment the link I did give and what Kingfischer told can help you.
Romke
What name I use there is not important only the three lines lower are important. I did test more and I think it is not a good idea to close OOo complete with macros. On this moment the link I did give and what Kingfischer told can help you.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Close OOo from a macro
Ignore my signature and use a macro language that resides outside of OpenOffice. Together with the udk link about automation that kingfisher mentioned the following VBScript code by Bernard Marcelly should do the trick:
Code: Select all
Set StarDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
StarDesktop.terminate
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Close OOo from a macro
Hello
It is not a real problem to close OOo. But the problem I find: I cannot startup again. The reason is it does not complete close OOo. When I kill all processes of OOo then I can startup again. This does me remember to an earlier version then with some version you can close a document and with an other version it was not possible or must do it in an other way.
Romke
It is not a real problem to close OOo. But the problem I find: I cannot startup again. The reason is it does not complete close OOo. When I kill all processes of OOo then I can startup again. This does me remember to an earlier version then with some version you can close a document and with an other version it was not possible or must do it in an other way.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OOo from a macro
I am getting some way with a vbscript opener but I am puzzled that it opens in Libre rather than OO. Windows file association is set to OO for ods. The other brain-teaser is that it only opens the sheet and does ask for permission to load the macro which does happen in OO.
It would seem that the OO developers would do well to implement a similar function to VBA 'application.quit' to avoid having to go around the houses to do it.
It would seem that the OO developers would do well to implement a similar function to VBA 'application.quit' to avoid having to go around the houses to do it.
OpenOffice 4 on Windows 7
- kingfisher
- Volunteer
- Posts: 2123
- Joined: Tue Nov 20, 2007 10:53 am
Re: Close OOo from a macro
Can't your script specify the application to use? Why not file a request for enhancement on the issues site? There's a tutorial on the tutorials board about filing a request or 'bug' report.
Apache OpenOffice 4.1.9 on Linux
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OOo from a macro
-errrrr no! I took the script direct from the link from your link at post 3. Trying to be clever, I reckoned that uninstalling LO would do the trick. Ha! Silly me. Script now cannot find the class from Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager").Can't your script specify the application to use?
Obviously the uninstall has removed that. I will now re-install OO and see what happens. It certainly is not made easy!
EDIT: Class restored, but it still does not trigger the security warning for macros.
OpenOffice 4 on Windows 7
Re: Close OOo from a macro
I'd probably use something like the Windows script I use to force users off some applications.
I have a batch file that runs on a schedule so at 2:00 am in the morning users are logged out of our ERP and OpenOffice.
Mostly - only if you are happy that there is nothinng you'll lose, but you can probably close any open processes inside a macro.
I think I'll use this to add a close button on my machine shop Tool Management System.
taskkill /F /IM soffice.bin
taskkill /F /IM soffice.exe
I have a batch file that runs on a schedule so at 2:00 am in the morning users are logged out of our ERP and OpenOffice.
Mostly - only if you are happy that there is nothinng you'll lose, but you can probably close any open processes inside a macro.
I think I'll use this to add a close button on my machine shop Tool Management System.
taskkill /F /IM soffice.bin
taskkill /F /IM soffice.exe
skidmog - Application Development
( OpenOffice 3.3 on Windows 7 )
( OpenOffice 3.3 on Windows 7 )
Re: Close OOo from a macro
Hello
Maybe this example can help you and other readers for closing OOo.
There is one problem I cannot solve: I cannot close the BASIC ide when this is running. You must do this by hand.
Be carefull when you test this code. Store first your data. I'm not sure if I have found all problems.
Romke
Maybe this example can help you and other readers for closing OOo.
There is one problem I cannot solve: I cannot close the BASIC ide when this is running. You must do this by hand.
Be carefull when you test this code. Store first your data. I'm not sure if I have found all problems.
Romke
- Attachments
-
- CloseExample04.odt
- Close OOo . Do this not for the first time with important data what is not stored.
- (13.98 KiB) Downloaded 1139 times
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OOo from a macro
Appreciated, RPG. I will have a look. It does seem that unlike VBA you cannot just 'quit' everything but, as you say, you need to shut down the IDE 'manually'.
OpenOffice 4 on Windows 7
Re: Close OOo from a macro
Hello
The last time I try to use as much of this list. Yesterday I did found SaveAll and now Quit. So I hope I can use them for making smaller code. But I think there is still a problem for closing the database. When the database is closed it is possible that not all data is stored. The database does have the possibilities to close all the files who belong to the databasedocument but they are not stored. The same can happens for data in the tables in the database. But this is maybe only true when you open the databasedocument and do not have a good connection.
Learning programming in the API is for me also difficult. I do also learn new things. The last time I do learn to use commands from the list I did point to. Using this table means also you are programming on an other higher level. I have the idea there several levels in the way you can programm in the API. It cost me a lot of time before I could see this. It cost me a lot of time use all the possibillities of loadcomponentfromUrl. This was special true when I use it for opening subcomponents in a database. In this case you can use special command for the the subcomponents. loadComponentWithArguments give also possibilities.
In the beginning I was sure I could better avoid the commands which use the arguments. The reason was I could not understand them. Now I do understand them better I have the idea it is good to use them. This is also true for using the commands who belong to the framework. For me it was true: I could only use those things when I better understand how OOo is working and did work in the way OOo expect.
I do tell this for several reason but one reason is: It is for most people difficult to make code for OOo. You can only master OOo when you try to understand it. For me was true when I did learn more about OOo it force me to work in the way OOo expect.
When I do find shorter code I will post. I hope you enjoy it.
Romke
The last time I try to use as much of this list. Yesterday I did found SaveAll and now Quit. So I hope I can use them for making smaller code. But I think there is still a problem for closing the database. When the database is closed it is possible that not all data is stored. The database does have the possibilities to close all the files who belong to the databasedocument but they are not stored. The same can happens for data in the tables in the database. But this is maybe only true when you open the databasedocument and do not have a good connection.
Learning programming in the API is for me also difficult. I do also learn new things. The last time I do learn to use commands from the list I did point to. Using this table means also you are programming on an other higher level. I have the idea there several levels in the way you can programm in the API. It cost me a lot of time before I could see this. It cost me a lot of time use all the possibillities of loadcomponentfromUrl. This was special true when I use it for opening subcomponents in a database. In this case you can use special command for the the subcomponents. loadComponentWithArguments give also possibilities.
In the beginning I was sure I could better avoid the commands which use the arguments. The reason was I could not understand them. Now I do understand them better I have the idea it is good to use them. This is also true for using the commands who belong to the framework. For me it was true: I could only use those things when I better understand how OOo is working and did work in the way OOo expect.
I do tell this for several reason but one reason is: It is for most people difficult to make code for OOo. You can only master OOo when you try to understand it. For me was true when I did learn more about OOo it force me to work in the way OOo expect.
When I do find shorter code I will post. I hope you enjoy it.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Close OOo from a macro
I dont understand what is real problem here? You can always shut down manually?
If you want to use macro which is not saving anything an not closing Basic IDE -window you may use this:
This Lopetus-macro seems to work day and night, with Quickstarter or without, in Windows and in Linux Mint. But I dont know if anybody really need it (-;
If you want to use macro which is not saving anything an not closing Basic IDE -window you may use this:
Code: Select all
sub Lopetus
Rem rutiini, joka lopettaa OpenOffice-istunnon
Rem EI TALLENNA MITÄÄN!
Rem Muokannut: Risto Jääskeläinen
Rem Part from A. Pitoynak
Dim oDesktop As Object, oDocs As Object
Dim oDoc As Object, oComponents As Object
Dim i as Integer 'i counts how many windows are open in OOo
i = 0
oComponents = StarDesktop.getComponents()
oDocs = oComponents.createEnumeration()
Do While oDocs.hasMoreElements()
oDoc = oDocs.nextElement()
oDoc.dispose()
Loop
Rem Nauhoitettua osuutta
rem ----------------------------------------------------------------------
rem define variables
'dim document as object
'dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
'document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
'dispatcher.executeDispatch(document, ".uno:Quit", "", 0, Array())
Wait 1000 'Tässä sen salaisuus?
dispatcher.executeDispatch(StarDesktop, ".uno:Quit", "", 0, Array())
end sub 'Lopetus
Apache OpenOffice 3.4. WVista (32bit) & Linux Mint 13 (64bit)
Re: Close OOo from a macro
Hello
The problem was not closing normal documents but closing also an open IDE and I did see also problems with closing databasedocuments with storing the data and modified forms.
Romke
The problem was not closing normal documents but closing also an open IDE and I did see also problems with closing databasedocuments with storing the data and modified forms.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OOo from a macro
Indeed, RPG, and thanks for the renewed interest here from risto. It is the closing of the iDE that I seek a la VB and this appears to be the sticking point.
OpenOffice 4 on Windows 7
Re: Close OOo from a macro
I have no experience with this topic (or similar), but I mention that Alt F4 closes applications in Windows and Ubuntu.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Close OOo from a macro
I dont understand what is real problem here? You can always take a bigger hammer?
Thats closing with IDE open or closed what ever. Nothing is saved.
Code: Select all
sub Lopetus2
Rem rutiini, joka lopettaa OpenOffice-istunnon
Rem EI TALLENNA MITÄÄN!
Rem Muokannut: Risto Jääskeläinen
Rem Part from A. Pitoynak
Dim oDesktop As Object, oDocs As Object
Dim oDoc As Object, oComponents As Object
oComponents = StarDesktop.getComponents()
oDocs = oComponents.createEnumeration()
Do While oDocs.hasMoreElements()
oDoc = oDocs.nextElement()
oDoc.dispose()
Loop
Wait 1000 'Ei voi olla ainakaan < 500 !
Rem Raaka peli, suljetaan prosessi käyttöjärjestelmän puolelta:
Shell("c:\windows\system32\taskkill.exe",2,"/F /iM soffice.bin")
end sub 'Lopetus2
Apache OpenOffice 3.4. WVista (32bit) & Linux Mint 13 (64bit)
Re: Close OOo from a macro
Hello ristoi
When you did read the complete thread and also the links in the beginning you can knew it was done.
Romke
When you did read the complete thread and also the links in the beginning you can knew it was done.
Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
Re: Close OOo from a macro
ristol,
Although you can dispose a document, it is probably safer to check the returned component to see if it supports close. if it does support close, you can use the macro to set the document to be "not modified", then simply close the document. Probably safer than dispose. Sadly I can't say why it might be safer, but it was the method recommended to me some years back. Perhaps it just feels "kinder" to not use dispose with no real benefit.
Although you can dispose a document, it is probably safer to check the returned component to see if it supports close. if it does support close, you can use the macro to set the document to be "not modified", then simply close the document. Probably safer than dispose. Sadly I can't say why it might be safer, but it was the method recommended to me some years back. Perhaps it just feels "kinder" to not use dispose with no real benefit.
-
- Posts: 118
- Joined: Wed Feb 15, 2012 9:35 pm
Re: Close OOo from a macro
Need to revisit this thread: whatever I try I get a 'Recovery' process afterwards. I am currently using ristoi's 'shell' solution to close the main programme since all other methods do the same, but I always seem to be left with a 'cannot close while Basic is running' warning requiring Task Manager and also bizarrely an 'Untitled1 writer' opens on re-running (The programme runs in Calc) . Ristoi's 'hammer' is obviously effective but I would prefer to close it via OO. I just need to close down the main without triggering a 'recovery' process. Any ideas? All dialogs are disposed, files are saved and closed. What else do I need to do?
OpenOffice 4 on Windows 7