Hello,

With OpenOffice Basic, I want to prevent a document from closing.
I tried this simple code, stored in a Writer document:

Option Explicit

Global dontClose As Object

Sub denyClose
if IsNull(dontClose)  then
dontClose = com.sun.star.embed.InstanceLocker.InstanceLockerCtor1(ThisComponent, com.sun.star.embed.Actions.PREVENT_CLOSE)
end if
End Sub

Sub allowClose
if not IsNull(dontClose)  then
  dontClose.dispose
  dontClose = Nothing
end if
End Sub


The code was tested on AOO 3.4.1 with Windows XP Home.
1 - I run macro denyClose. I still can close the document.
2 - I load the document again, I run macro denyClose. Then I run macro allowClose : the document closes.

I changed the argument ThisComponent to : StarDesktop.CurrentFrame

I run macro denyClose. I can't close the document. But OpenOffice freezes and I have to kill it.

Does anybody have a working code in Basic ?

Regards
  Bernard

Reply via email to