A focus rectangle is displayed on all list items in VBA

I created a Userform in Excel VBA that has an unrelated list that has the MultiSelect property set to Extended. When this list receives focus by any means other than clicking on a list item, all the items in this list are displayed with a rectangle with focus points around them.

Here is some code that shows a phenomenon next to another list for which MultiSelect is set to Single for comparison. Create a Userform, place two lists on it and add the code to the form. When you run the form, go to the tab between the lists to see what I 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 focus rectangles or prevent them from appearing?

Thanks,

+4
source share
1 answer

I experimented with your code in Excel 2010 and confirm your observation. If I create two lists, enter the code provided, run the form and click the tab to focus on ListBox2, the dashed lines will appear around all the lines.

If I create two lists as before, manually set ListBox2 / Properties / Multiselect to 2 - fmMultiSelectExtended , run and drag the nasty disapperar lines into ListBox2.

For me it is quite stable, the form now survives in several changes to the window activation, jumpng back / forward, etc.

don't ask me why ...

+1
source

Source: https://habr.com/ru/post/1446034/


All Articles