About VBA-UserForms

Hello community people!

I came across with a problem, with porting VBA-forms to LibreOffice Basic environment. I have a couple of VBA-forms (MS_Forms) which I’ve exported from a VBA-project in LibreOffice Basic designer as .xdl and then imported to my LibreOffice Basic tuning.
On the main dialog I have a multitab control on which are several controls (such as textboxes, dropdown boxes and so on…). All controls placed on tabs are seen at runtime but are not seen at design mode.

The controls that are seen on design mode can be bound to event routines (sub-programs in the macro) as usual with just a couple of mouse-click. But I haven’t found a way to create an event listener for the controls which are not visible on design mode :thinking:

I would be very grateful if anyone happens to know a way around this problem and share his/her knowledge with me and others :hugs:

EDIT: Information in visual form.

The view a runtime:
Screenshot_at_runtime

The view in design mode (edited so that the entire dialog (the controls seen) fits the picture):
Screenshot_on_design_mode

In order to understand, it is probably necessary to upload the original file *.xlsm, then .xdl, .ods.

https://www.pitonyak.org/book/AndrewMacro.odt (Chapter 14 1. »Handlers and Listeners«)

Thanks, but unfortunately the link you provided is dead. I am aware of how the event listener can be built and so on. That’s not the problem, but how to get handle to the controls which are invisible in designer. And foremost, is the tabs object defined in some of UNO service so it can find possible child controls placed on a tabs object. If I can get the handle to these controls I can use a structure (type) and give them properties and then collect all into an array and so on…

Here’s an example of the codebehind my VBA UserForm.

No, there are no tabs in StarBasic. StarBasic dialogs support “steps”. Steps control the visibility of selected controls. Controls with Step=0 are always visible. Controls with Step=1 are visible when the dialog has Step=1 and so on.
StepDialogDemo.ods (20.0 KB)

So there’s no easy way around this. It seems that I need to place the controls in four group boxes and set a button for each one so that the associated group box appears while the others will be hidden. Thanks anyway.

You have to rebuild the entire VBA application. VBA is the ring to bind them all, forever and ever.

That’s how I understood it.

@Villeroy
You clearly have clairvoyant gifts!

Damned, I should have checked first what is going on nowadays…
The latest API (07.02.2025) contains so many changes compared to API (07.07.2009) which I used in my old VBA-tuning that I have to code everything again from the beginning or forget the whole thing. :woozy_face:

Here’s the result :upside_down_face:

I couldn’t give it up and this is the result:

Sub ListDialogControls
	
	Dim myMultiPage As Variant
	Dim myMultiPageControl As Variant
	
	Dim i As Integer, j As Integer, k As Integer, ctlName As String
	
	For i = 0 To uBound(MyForm1.getControls())
		If MyForm1.getControls()(i).Model.Name = "MultiPage1" Then
			myMultiPage = MyForm1.getControls()(i)
			For j = 0 to uBound(myMultiPage.getControls())
				ctlName = myMultiPage.getControls()(j).Model.Name
				If myMultiPage.getControls()(j).Model.Name = ctlName Then
					myMultiPageControl = myMultiPage.getControls()(j)
					For k =  0 To Ubound(myMultiPageControl.getControls())
						MsgBox myMultiPageControl.getControls()(k).Model.Name
					Next k
				End If
			Next j
		End If
	Next i
	
End Sub

:heart_eyes:

Also the property values ​​set for the controls still exist, they can be found and, if desired, set new values. The code can be found here

I would be grateful, if you could post a sample document with that code. I did not touch Excel in 23 years. Microsoft products (other than their darned operating system) are not allowed on our computers. Therefore, I have no objects your code could relate to, and LO can’t create those objects.

Which do you want, the native VBA or the LibreOffice Basic tuning I’m working on now, or maybe both?

Anything that makes variable myMultiPageControl inspectable in LibreOffice.

MHLO.ods (18.7 KB)

1 Like

An example of dynamically adding listeners for dialog controls is in the famous book by Andrew Pitonyak OOME_4_1.odt, listing “Create the dialog, the controls, and the listeners.”

As far as I understand the matter, the sample document MHLO.ods includes a multi-page dialog generated by MSO which can not be generated with LibreOffice. I did not know, that LO can show the multi-page dialog anyway.

The com.sun.star.awt.UnoControlMultiPage and com.sun.star.awt.UnoControlPage services are not documented and therefore should not be used in any case.

@sokol92:

Thanks, but I already found this document while digging online.

@sokol92:

I have no idea what com.sun.star - services or whatsoever the Basic Designer uses. I simply exported couple of UserForms from my old Excel/VBA -project and I think the MultiPage control looks good when it’s visible. I myself don’t give a much about what some documentation says or not say, but I like this control object and the challange it causes.