Suppressing Pop-Up Error Messages in VBA Macros

I’m writing some VBA macros and would like to suppress any pop-up errors that occur. For instance, let’s say I have a block of code that looks like this:

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "junk"

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

I would like that to fail silently, but I get an “Invalid range” pop-up instead. Is there a way to turn these pop-ups off?

This is not VBA, this is LOBasic.
In most cases, to manipulate a cell, you do not need to go to it or select it.
But if you want to.

	cc = ThisComponent.CurrentController
	
    active_sheet = cc.ActiveSheet
 
    range = active_sheet.getCellRangeByName( "A1:E5" )
 
    cc.select(range)

If range name not exists, you can control this error:

Sub Main
	On Error GoTo control_error
	
	cc = ThisComponent.CurrentController
	
    active_sheet = cc.ActiveSheet
 
    range = active_sheet.getCellRangeByName( "not_exists" )
 
    cc.select(range)
    
    Exit Sub

control_error:
	MsgBox "Not exists"
     
End Sub

Okay, thank you. What’s the difference between VBA and LOBasic?

VBA is for MSOffice ( :nauseated_face:), LOBasic is for ours LibreOffice. :smiling_face_with_three_hearts:

Ohhh…I’ve seen other people use the term “VBA” when talking about LO macros, so I didn’t realize it was Microsoft-specific. Thank you for the clarification!

Yes it is a common mis-conception to see LO as a drop-in replacement.

The part, wixh is common is the laguage BASIC itself, but even there are differencies. The API to access documents and available functions are quite different. Open/LibreOffice is based on UNO.
.
And then there is a flag to set to help port ing/using some VBA-macros: VBAsupport 1

https://wiki.documentfoundation.org/Documentation/BASIC_Guide#:~:text=VBA%20%3A%20Compatibility%20between%20LibreOffice%20Basic,concepts%20provided%20in%20LibreOffice%20impossible).

1 Like