I've created a Userform in Excel VBA, on which there is an unbound Listbox that has its MultiSelect property set to Extended. When that listbox receives focus by any means other than clicking a list item, all items in that list appear with the dotted focus rectangle around them.
Here is some code that shows the phenomenon beside another listbox with MultiSelect set to Single for comparison. Create a Userform, put two Listboxes on it, and add the code to the form. When you launch the form, tab between listboxes to see what I've described.
Private Sub UserForm_Activate()
ListBox1.MultiSelect = fmMultiSelectSingle
ListBox2.MultiSelect = fmMultiSelectExtended
Dim i As Integer
For i = 1 To 15
ListBox1.AddItem String(i, Chr(i + 64))
ListBox2.AddItem String(i, Chr(i + 64))
Next
End Sub
Is there a way to remove the focus rectangles or prevent their appearing?
Thanks,
ListIndex
property after filling the ListBox - i.e.ListBox2.ListIndex = ...
Using -1 and 0 puts the focus on everything; 1, 2 and 3 put the focus on a single line and 4 or higher puts the focus on everything. This is with Excel 2003 though. Also different effects if the ListBox MultiSelect property is set in the properties pane in the UserForm design screen rather than via VBA – barrowc