How does one interrupt a running macro?

I’m studying LibreOffice Basic for macros. I have a long-running macro which, once I determine a bug, I would like to abort the macro. I’ve tried CTRL-C but that does not work. I’m running on Linux, if that matters. I am grateful for any insight into this issue.

Hello,

Much of the information regarding LO can be found in the many locations of LO help. Off-line help (if you installed it) states to use Ctrl+Shift+Q from within the Basic IDE. Shift+F5 also works in the IDE as well as pushing the Stop Macro toolbar button.

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

This is the correct answer. Although it’s in the offline documentation, I could not find it online. The only official information online is the bug report at 70598 – Basic IDE - no way to stop a macro in an infinite loop.

For online see the 5.4 Help which came from here. The Shift+F5 came from hovering the mouse over the Stop icon.

Hello @theGeeko61,

For simple debugging i often just use the msgbox() function.

Code execution is halted until the msgbox dialog is dismissed.

So you could temporarily insert the following line into your code, at all places where you would like to be able to stop the macro:

If msgbox( "Should we STOP the Macro here?", 36 ) = 6 Then Stop

HTH, lib

You can add a temporary print statement to your macro. This works much like msgbox but has two option buttons; OK continues but Cancel aborts the macro. I often combine this with xray, which provides the detailed information I need to determine whether I’ve found what I’m looking for but has no abort option. xray object : print. This is especially useful when the time between xray statement invocations is too short for Ctrl+Shift+Q to work.

1 Like

Pull down “Run”. All your options are there. When done compile, to make sure it still is able to run.
I do very little in Macro’s, but, to go to a macro to work in it. Toos/Macros/edit macros. Then in Object Catalog go to your file, then Standard then your Module, double click your Module or the Sub you are wanting to work in. Seems you already know how to do those steps.
Click in your Sub where you want it to stop, then pull down “Run”. All your options are there. When done compile, to make sure it still is able to run.

What a lot of these solutions do not say is that if your macro repeatedly displays a message box (as in the question at Fast Macro code, how to interrupt, stop? - #7 by PhranceQueTara ), you have to open or switch to a different document, as the message box stops the IDE getting the focus, meaning the other solutions do not work.

Once you are in the other document, press Ctrl-Alt-Q, and a message box says “The macro running has been interrupted”. Once you dismiss that, and then dismiss the message box your macro was showing, you can observe that your macro is indeed stopped.