Fast Macro code, how to interrupt, stop?

How to interrupt running Basic Macro code, when the main IDE-window does not have focus?
The following example is rather silly, but illustrates my question.
When running the script below from within the IDE by clicking the run button in the menu, then focus goes to the Msgbox, and “pretty much” stays there.

Sub EndlessMsgBox
	Do Until False
		Msgbox("Hello World")
	Loop
End Sub

These Interrupt-Attempts did not work:

  • Ctrl+Shif+Q does not work
  • Shift+F5 does not work
  • None of the IDE buttons nor pulldowns work, because don’t have focus.
  • Can’t exit IDE, because because doesn’t have focus.

Any insight is appreciated.
(LO 7.0.2.2, Windows 10)

I figured out a somewhat clumsy way, don’t know why or how works:

  • Go into the main LO_Base window, and click Menu/Tool/Macro/Run Macrocs…
  • Then select the exact same Macro you want to interrupt and click the [Run] button
  • Go back into the IDE-window
  • Now, after clicking the [OK] button inside the Msgbox, code halts and lets me stop it.

I’m sure there’s a more elegant way than that. LMK.

Hello,

You can set a breakpoint (circle with dot left of code line) then be able to step or cancel:

image description

See → LibreOffice Basic IDE

and → Integrated Development Environment (IDE)

Sure, I agree, break-points are great to use during debug, when planning to set them before running code, and when setting them upfront (basically when anticipating code issues).

But how to interrupt already running code, if the focus is not passed back to the IDE? (or, as in my silly example, if focus is only passed back to the IDE for a brief moment, not long enough for manual interrupts).

Assumptions:

  • No break-points were set
  • No other escape mechanisms added to the code itself

I could imagine that somewhere within LO exists some sort of an interrupt handler, where maybe custom keyboard shortcuts could be tied to setting specific interrupt flags, or similar. If the keyboard shortcut Ctrl+Shift+Q (or equivalent) was intended to do so, maybe its interrupt “rights” could somehow be “elevated or extended” to running code (in this particular example: the Msgbox routine).

I tried my example again.

This time neither the LO-Base-main-window, nor the IDE-window would take focus, so could not access any IDE or LO functions.

Probably could have killed it via Windows Task Manager [Ctrl+Alt+Del], but to get out of the running code, I did this:

  • Open a completely different LO_Base
  • Click Menu/Tool/Macro/Run Macrocs…
  • Select under [Library]: LibreOffice Macros/Access2Base/Methods/
  • Select under [Macro Name]: _Refresh
  • Click the [Run] button (this will throw an error, but don’t care)
  • Go back into the IDE-window

Now, after clicking the [OK] button inside the Msgbox, code halts and lets me stop it.

Your conditions are not reasonable. In this case simply kill the process & fix the terrible code.

Yes, indeed possible, as indicated in the example below, but my question still is:

How to interrupt running Basic Macro code, when the main IDE-window does not have focus?

All answers I could find so far (in other threads & this thread) require that one can access the functions of the IDE-window. But what to do if one finds themselves in a situation, where one does not have access to the IDE-functions, because code is putting focus one other objects (= Msgbox in this case).

How to interrupt the code then? In the old VBA days I tend to remember that it was possible with a full keyboard to exit out of code with [Ctrl]+[Pause/Break], or similar.

Below is my quick example on how to programmatically break out, but again, only possible while one has access to the IDE-functions.

Sub EndlessMsgBoxWithCancel
	Do Until False
		If Msgbox( "Continue?", MB_OKCANCEL ) = IDCANCEL Then Stop
	Loop
End Sub