Reason: tagged [Solved].
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
KF - I had not thought of running via a script.
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.
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
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
I think after this you can close OOo. But I have not test it.
I have no example code.
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.
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
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.
Code: Select all
Set StarDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop") StarDesktop.terminate
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.
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.
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.
-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.
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
( OpenOffice 3.3 on Windows 7 )
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.
- Close OOo . Do this not for the first time with important data what is not stored.
- (13.98 KiB) Downloaded 865 times
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.
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
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.
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
- Posts: 186
- Joined: Sun Oct 07, 2007 9:13 pm
- Location: Columbus, Ohio, USA
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.
LO and AOO on Fedora