Macro (starDesktop.terminate) makes libre calc crash?

When I close libre calc with macro , libre calc close but give a crash message

my code

ThisComponent.close(True)
Wait 400
starDesktop.terminate
end sub

Any suggestion?

aed

Hello,

Had no problem running with TDF(The Document Foundation version) LO v7.1.5.2 on Ubuntu 20.04.2

Of course this closes almost all open items of LibreOffice.

My version which has problem is
TDF(The Document Foundation version) LO v7.1.1.2 WIN10-64

I used TDF(The Document Foundation version) LO v7.1.5.2 WIN10-64
and still there’s problem

Hello,

You should always include LO version and OS with questions. It may be the difference.

Switched to Win-10 and using the macro you posted had no problem:

Version: 7.1.4.2 (x64) / LibreOffice Community
Build ID: a529a4fab45b75fefc5b6226684193eb000654f6
CPU threads: 8; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded

Either something else in your code or maybe an issue with user profile (LibreOffice user profile).

My code starts when a file is opened (using macro >> customize>> event)
It deletes some rows and columns adding texts
and saves file.csv
It works fine
and close libreCalc but with crash message

REM ***** BASIC *****

sub Main
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = “ToPoint”
args1(0).Value = “$B$1:$B$23”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = “Flags”
args2(0).Value = “R”

dispatcher.executeDispatch(document, “.uno:DeleteCell”, “”, 0, args2())

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = “ToPoint”
args3(0).Value = “$A$13:$B$14”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args3())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = “ToPoint”
args4(0).Value = “$A$13”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args4())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, “.uno:DeleteCell”, “”, 0, Array())

rem ----------------------------------------------------------------------
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = “ToPoint”
args6(0).Value = “$A$13:$B$13”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args6())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = “Flags”
args7(0).Value = “C”

dispatcher.executeDispatch(document, “.uno:DeleteCell”, “”, 0, args7())

rem ----------------------------------------------------------------------
dim args8(0) as new com.sun.star.beans.PropertyValue
args8(0).Name = “ToPoint”
args8(0).Value = “$D$16:$N$17”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args8())

rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = “Flags”
args9(0).Value = “C”

dispatcher.executeDispatch(document, “.uno:DeleteCell”, “”, 0, args9())

rem ----------------------------------------------------------------------
dim args10(0) as new com.sun.star.beans.PropertyValue
args10(0).Name = “ToPoint”
args10(0).Value = “$A$1”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args10())

rem ----------------------------------------------------------------------
dim args11(0) as new com.sun.star.beans.PropertyValue
args11(0).Name = “StringName”
args11(0).Value = “y”

dispatcher.executeDispatch(document, “.uno:EnterString”, “”, 0, args11())

rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = “ToPoint”
args12(0).Value = “$B$1”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args12())

rem ----------------------------------------------------------------------
dim args13(0) as new com.sun.star.beans.PropertyValue
args13(0).Name = “StringName”
args13(0).Value = “x”

dispatcher.executeDispatch(document, “.uno:EnterString”, “”, 0, args13())

rem ----------------------------------------------------------------------
dim args14(0) as new com.sun.star.beans.PropertyValue
args14(0).Name = “ToPoint”
args14(0).Value = “$C$1”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args14())

rem ----------------------------------------------------------------------
dim args15(0) as new com.sun.star.beans.PropertyValue
args15(0).Name = “StringName”
args15(0).Value = “z”

dispatcher.executeDispatch(document, “.uno:EnterString”, “”, 0, args15())

rem ----------------------------------------------------------------------
dim args16(0) as new com.sun.star.beans.PropertyValue
args16(0).Name = “ToPoint”
args16(0).Value = “$E$11”

dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args16())

rem ----------------------------------------------------------------------
dim args17(2) as new com.sun.star.beans.PropertyValue
args17(0).Name = “URL”
args17(0).Value = “file:///C:/Users/me/Desktop/file.csv”
args17(1).Name = “FilterName”
args17(1).Value = “Text - txt - csv (StarCalc)”
args17(2).Name = “FilterOptions”
args17(2).Value = “44,34,IBMPC_850,1,0,false,true,false,false,false”
dispatcher.executeDispatch(document, “.uno:SaveAs”, “”, 0, args17())

ThisComponent.close(true)
Wait 1500
starDesktop.terminate
end sub

And if you eliminate everything but:

Sub closeLO
ThisComponent.close(True)
Wait 400
starDesktop.terminate
end sub

does it still crash?

@AT825 tested with your complete code (changed csv URL for my system) and had no problem in either Ubuntu 20 or Win 10.

closes but crashes too
I will try with other pc

Also don’t know if you have 32 or 64 bit LO - testing was all 64-bit.

LO v7.1.5.2 (64) WIN10-64
I tried with another pc
Lo crashs

Sorry, no other ideas. As mentioned, this worked on two different OS’s without any issues for me.

Definitely not enough info. A sample file is needed. And possibly a screencast.

The script starts with closing current component, and then proceeds with terminating the application - but the component containing the script is already unloaded. Are there any other scripts assigned to events (both in the file, and on the application level)? Are there other windows open at the moment of closing the application? Which (other documents/IDE/dialogs)? What is their status?

Where’s the code located?
I rarely use recorded macros, but in the few cases I do, I store the Sub to the document (as opposed to the Standard library of ‘My Macros…’ for my LibreOffice).
Looking over the highly specialized code posted above, I would assume that its location also is “=document” as opposed to “=application”.
I wouldn’t expect any macro running from document location to finish successfully after the document containing it was closed.
An (untested) workaround might be to use a final statement calling an unspecific macro located in the application’s standard library like

Sub specializedLocalCode()
  REM Lots of lines of code
  ...
  REM final statement of the local macro:
  tryUnspecificClose(ThisComponent)
End Sub

REM a portion of a module in the Standard library of the application.
Sub tryUnspecificClose(pComponent)
  pComponent.Close(True)
  REM  additional statements as needed...
  Wait 1000
  StarDesktop.terminate()
End Sub  

[Edit] Meanwhile tested. Worksforme.[/Edit]

There was no clarification to the questions I posted above; and also it’s interesting if there are some extensions present? Does it also crash using safe mode?

Had noted in my second comment that it may be an issue with the user profile. Provided a link but no response on that.

1 Like

Download the attached example to a location where you have the right to write, open it denying document macros, check the contained code for the absence of malign parts, do with the contained XX-named Sub as explained, close the Basic IDE, reload the document permitting document macros now, make sure that the Basic IDE is closed, and call the macro specializedLocalCode() from the document.
This works for me demonstarting how my above suggestion should be implemented.
closeDocAndDesktopIfAllowed.ods (10.0 KB)

It closes but with crash message as before :neutral_face: :neutral_face:

It was doubtable fun to rework the monster macro, and to integrate it with the local part of the pair of macros I posted earlier and expect to be needed to get what you want.
Not doubtable at all is the fact that -if there isn’t much more about the macro than found in your post- you never can save the time you (and me) wasted it developing it by using it. That’s the case with many macros, however.

See new attachment: applyCloseDocAndDesktopIfAllowedBefore.ods (45.3 KB)
Don’t forget to provide the second macro in the application’s Standard library as mentioned earlier.

Anyway: It works for me flawlessly, and I will now be absent from this thread.

My macro is auto-recorded
I did not write from zero
Your last file also has same problem
Thank you for your help
My be some users can confirm if it works for them without any crash message