| View previous topic :: View next topic |
| Author |
Message |
OisÃn_ General User


Joined: 31 Jul 2006 Posts: 42 Location: Dresden, Germany
|
Posted: Fri Sep 29, 2006 2:57 am Post subject: Runing macro when document is closed [solved] |
|
|
Under Tools -> Configure -> Events in Writer there are two events regarding the closing of a document: Document close and Document is closing (in German i.e Dokument schließen and Dokument wird geschlossen.
The first is executed before the user is asked whether he is sure and whether he wants to save and the second is executed when the document is really closed. In my case, I want to implement the second but here is my problem: Writer seems to dispose the basic code before the macro is executed thus throwing an error upon closing the document.
To reproduce try the following:
- Create a new Writer document
- Create a macro. eg: | Code: | Sub DocumentIsClosing
msgbox "DocumentIsClosing"
End Sub |
- Tools -> Configure -> Events -> Document is closing -> Assign --> select the unnamed document -> Standard -> Modul1 -> DocumentIsClosing --> OK --> OK
- save the document
- close the document --> Error in scripting framework: BasicProviderImpl::getScript: no script!
What am I doing wrong? How can I execute a macro upon closing a document?
Thanks a lot for any ideas. _________________ There are 10 types of people in the world - those who understand binary and those who don't.
Last edited by OisÃn_ on Sun Oct 08, 2006 10:17 pm; edited 1 time in total |
|
| Back to top |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3323
|
Posted: Fri Sep 29, 2006 4:29 am Post subject: |
|
|
I think you will need to put the macro in another library - not in a library of the document which is closing / has closed. It could go into the Standard "My Macros & Dialogs" library. _________________ search forum by month |
|
| Back to top |
|
 |
OisÃn_ General User


Joined: 31 Jul 2006 Posts: 42 Location: Dresden, Germany
|
Posted: Fri Sep 29, 2006 5:10 am Post subject: |
|
|
@noranthon
If I understand this correctly I have to install a library with this macro on the user's computer. Am I right?
Here is my scenario: I have an form that the user can load via a webclient. The fields in the form are generated just before download. Upon opening the document I assign Listeners to some of the controls in the form. These have to be cleared when the document is closed because OOo crashes when this isn't done (see Crash on closing OOo with TextListeners in form using Basic).
If I have some code in an external library the user has not only to download the form to fill but also the library and he has to install the library which is too complicated for the average user! Thus I want all my code in the document that the user downloads.
IMO this is a bug in OOo. My suggestion would be that either OOo clears all listeners itself without crashing or that the code of macros is executed just before the document is closed, the same as it is done in Word AFAIK. _________________ There are 10 types of people in the world - those who understand binary and those who don't. |
|
| Back to top |
|
 |
OisÃn_ General User


Joined: 31 Jul 2006 Posts: 42 Location: Dresden, Germany
|
Posted: Fri Oct 06, 2006 1:24 am Post subject: |
|
|
| Oisín_ wrote: | | IMO this is a bug in OOo. My suggestion would be that either OOo clears all listeners itself without crashing or that the code of macros is executed just before the document is closed, the same as it is done in Word AFAIK. |
Reported as issue #70149 _________________ There are 10 types of people in the world - those who understand binary and those who don't. |
|
| Back to top |
|
 |
Zarius OOo Enthusiast


Joined: 21 Jan 2005 Posts: 142 Location: Brisbane, Australia
|
Posted: Sun Oct 08, 2006 5:01 pm Post subject: |
|
|
Hi Oisín,
In the meantime there is another way to do this and still keep the macro within the document. The code below is stored within the documents' macro & attached to the "open document" (or "create document" for a template) event. It registers an event listener - then when the document is closed the second function is called before the document is actually disposed of (& after the "do you wish to save" prompt). I've tested it in Staroffice 7 & OOo 2 and had no issues so far.
| Code: | sub Doc_event_OpenDocument()
' Create an event listener object.
' The object is an internal implementation provided by the OOo Basic.
' When the disposing event of the listener is called, then the
' event listener object created by Basic will call the global
' sub with the name we asked for, plus the event name.
oEventListener = CreateUnoListener( "ThisDocCloseListener_", "com.sun.star.lang.XEventListener" )
' Plug the event listener into this document.
ThisComponent.addEventListener( oEventListener )
End Sub
Sub ThisDocCloseListener_disposing( oEvent )
MsgBox( "The document " + oEvent.Source.URL + "is being disposed of." )
End Sub
|
_________________ Zarius Tularial. (WinXP - OOo 1.1.4, FedoraCore 4 - OOo 2.0, RHEL4 - StarOffice 7)
Quoots - a quicker way to open your documents and fill in template details in OOo. (written in OOBasic) |
|
| Back to top |
|
 |
OisÃn_ General User


Joined: 31 Jul 2006 Posts: 42 Location: Dresden, Germany
|
Posted: Sun Oct 08, 2006 10:16 pm Post subject: |
|
|
| Zarius wrote: | Hi Oisín,
In the meantime there is another way to do this and still keep the macro within the document. (....) It registers an event listener - then when the document is closed the second function is called before the document is actually disposed of (& after the "do you wish to save" prompt). (....) |
Thanks a lot. That works like a charm  _________________ There are 10 types of people in the world - those who understand binary and those who don't. |
|
| Back to top |
|
 |
|