[Solved] Close OOo from a macro

Creating a macro - Writing a Script - Using the API

[Solved] Close OOo from a macro

Postby mike phillips » Sun Mar 25, 2012 11:17 am

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].
OpenOffice 4 on Windows 7
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OO from a macro

Postby RPG » Sun Mar 25, 2012 11:55 am

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OO from a macro

Postby kingfisher » Sun Mar 25, 2012 12:15 pm

This may be of interest also: Automating OpenOffice on Windows and session manager.
Apache OpenOffice 4.1.2 (64 bit) on PCLinuxOS
User avatar
kingfisher
Volunteer
 
Posts: 2109
Joined: Tue Nov 20, 2007 10:53 am

Re: Close OO from a macro

Postby mike phillips » Sun Mar 25, 2012 12:40 pm

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.
OpenOffice 4 on Windows 7
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OO from a macro

Postby RPG » Sun Mar 25, 2012 1:30 pm

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OO from a macro

Postby mike phillips » Sun Mar 25, 2012 2:47 pm

Solution close first the dialog and then close OOo

There's the problem. 'Basic' still runs.This is the latest incarnation.
Code: Select all   Expand viewCollapse view
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
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OO from a macro

Postby RPG » Sun Mar 25, 2012 3:06 pm

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OO from a macro

Postby RPG » Sun Mar 25, 2012 3:17 pm

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
    Default button :Yes
    State
    Button type
When you set the buttons properties well then you can close the dialog. The dialog.execute can give back a return value of 0 or 1.
I think after this you can close OOo. But I have not test it.
I have no example code.

Romke
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OO from a macro

Postby RPG » Sun Mar 25, 2012 3:43 pm

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
Code: Select all   Expand viewCollapse view
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


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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OO from a macro

Postby mike phillips » Sun Mar 25, 2012 6:13 pm

Hulp. ?? Is that a typo?
OpenOffice 4 on Windows 7
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OO from a macro

Postby RoryOF » Sun Mar 25, 2012 6:15 pm

It is Dutch for Help.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25509
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Close OO from a macro

Postby mike phillips » Sun Mar 25, 2012 6:26 pm

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
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OOo from a macro

Postby RPG » Sun Mar 25, 2012 10:04 pm

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OOo from a macro

Postby rudolfo » Sun Mar 25, 2012 11:12 pm

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   Expand viewCollapse view
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.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Close OOo from a macro

Postby RPG » Sun Mar 25, 2012 11:52 pm

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OOo from a macro

Postby mike phillips » Mon Mar 26, 2012 12:21 pm

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.
OpenOffice 4 on Windows 7
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OOo from a macro

Postby kingfisher » Mon Mar 26, 2012 1:16 pm

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.2 (64 bit) on PCLinuxOS
User avatar
kingfisher
Volunteer
 
Posts: 2109
Joined: Tue Nov 20, 2007 10:53 am

Re: Close OOo from a macro

Postby mike phillips » Mon Mar 26, 2012 2:46 pm

Can't your script specify the application to use?
-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").

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
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OOo from a macro

Postby skidmog » Sun Apr 08, 2012 5:49 am

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
skidmog - Application Development
( OpenOffice 3.3 on Windows 7 )
skidmog
 
Posts: 6
Joined: Fri Jul 15, 2011 6:14 pm

Re: Close OOo from a macro

Postby RPG » Sat Apr 21, 2012 11:07 pm

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
Attachments
CloseExample04.odt
Close OOo . Do this not for the first time with important data what is not stored.
(13.98 KiB) Downloaded 491 times
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OOo from a macro

Postby mike phillips » Sun Apr 22, 2012 9:05 am

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
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OOo from a macro

Postby RPG » Sun Apr 22, 2012 11:10 am

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OOo from a macro

Postby ristoi » Wed Aug 15, 2012 10:22 pm

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:
Code: Select all   Expand viewCollapse view
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


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 (-;
Apache OpenOffice 3.4. WVista (32bit) & Linux Mint 13 (64bit)
ristoi
 
Posts: 8
Joined: Wed Aug 08, 2012 7:01 pm
Location: Järvenpää, Suomi

Re: Close OOo from a macro

Postby RPG » Wed Aug 15, 2012 11:55 pm

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
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OOo from a macro

Postby mike phillips » Thu Aug 16, 2012 8:41 am

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
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Re: Close OOo from a macro

Postby RoryOF » Thu Aug 16, 2012 8:59 am

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.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25509
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Close OOo from a macro

Postby ristoi » Thu Aug 16, 2012 9:07 am

I dont understand what is real problem here? You can always take a bigger hammer?

Code: Select all   Expand viewCollapse view
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


Thats closing with IDE open or closed what ever. Nothing is saved.
Apache OpenOffice 3.4. WVista (32bit) & Linux Mint 13 (64bit)
ristoi
 
Posts: 8
Joined: Wed Aug 08, 2012 7:01 pm
Location: Järvenpää, Suomi

Re: Close OOo from a macro

Postby RPG » Thu Aug 16, 2012 9:20 am

Hello ristoi

When you did read the complete thread and also the links in the beginning you can knew it was done.

Romke
LibreOffice 5.3.6.1 on openSUSE Leap 42.3
RPG
Volunteer
 
Posts: 2102
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Close OOo from a macro

Postby pitonyak » Fri Sep 07, 2012 4:38 pm

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. :knock:
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
pitonyak
Volunteer
 
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: Close OOo from a macro

Postby mike phillips » Mon Mar 03, 2014 9:03 pm

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
mike phillips
 
Posts: 118
Joined: Wed Feb 15, 2012 9:35 pm

Next

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests