S_Leonardo
10 years agoOccasional Contributor
Problem showing a listbox with selected items using .ShowModal
Hi, I got some difficulties trying to load a listbox with some selected items using .ShowModal Example of my code(VBScript): With UserForms.MyForm.ListBoxABC .Add("Test_01") .Add("Test...
- 10 years ago
The form is not yet shown when you are setting the selected property of the item and therefore cannot be set.
You need to add an event handler for the OnShow event of the userform and set the selected property after the form is shown.
With UserForms.MyForm.ListBoxABC .Add("Test_01") .Add("Test_02") .Add("Test_03") End With ' UserForms.MyForm.ShowModal Sub OnShow_Handler(Sender) 'Set this handler under the events section for the form in the designer UserForms.MyForm.ListBoxABC.Selected( 0) = True End Sub
Reference event handling here.