Can anyone please give a simple example of how to set a ComboBox to a specific index via a macro.
Welcome!
How about just setting the control’s Text property to the value you want? Simply select the desired line from the list of elements by index and write it in the control text field.
Sub callSetIndex
Dim oSheet As Variant
Dim oForm As Variant
Dim oControl As Variant
Dim i As Long
oSheet = ThisComponent.getCurrentController().getActiveSheet()
oForm = oSheet.getDrawPage().getForms().getByIndex(0)
oControl = oForm.getByName("Combo Box 1")
For i = 1 To oControl.ItemCount
oControl.Text = oControl.getItemText(i-1)
Wait 500
Next i
For i = oControl.ItemCount To 1 Step -2
oControl.Text = oControl.getItemText(i-1)
Wait 500
Next i
For i = 1 To oControl.ItemCount Step 3
oControl.Text = oControl.getItemText(i-1)
Wait 500
Next i
End Sub
Thank you for the quick response.
Your answer was exactly what I was looking for.
Because I had the code in place to add the list values all I ended up needing was the one line that set the control to a specific text as recommended.
I actually wanted to set the control to the first item so used:
oControl.Text = oControl.getItemText(0)