问题
In Excel 2007 SP3, I have a workbook with a multi-column, multi-select ActiveX listbox. On most computers it works fine. But on one user's computer, when I read from that listbox and write data from it to another sheet, it's font gets smaller. And smaller again each time the command button that does task is clicked.
All of our computers are on Excel 2007 SP3 and Windows 7. Only one of them has this problem; it works fine on the others.
Stepping through the code on the affected computer, I found that when the problem happened, the listbox still reported a font size of 12 (the original, correct font size), even though the actual displayed font was clearly smaller.
When I set the listbox's font size to 12, nothing happened.
However, when I set the font size to 10, then it changed to 10. And when I then changed it to 12, it went back to 12 and looked right. However, that changed the listbox's height and width, and deselected any of the user's selections in it (as I mentioned it's on multi-select).
As you many know, a workaround is required to set the listbox's height to a precise height that will allow the last visible item in it at the bottom to be selected. That workaround has to be rerun each time that button is clicked.
But there are still two problems on the affected computer: - First, even though I turn ScreenUpdating off during the whole process, it still takes about half a second on a fast computer to resize it, and during that time the user sees the strangely small listbox font. - Second, even though I'm telling the height and width to be the same each time, they end up different sizes each time, cyling through at least 3 sizes each. So that looks strange to the user too. I forgot to test while at that user's computer whether the last visible list item was selectable per the workaround, and it will be some time before the next opportunity.
So -- any suggestions?? Again I don't know of any different in configuration between the affected computer and the others. Same Excel version, same service pack, same version of Windows.
回答1:
I tried, in VBA, resizing ActiveX controls to their original top,left, width, height. This didn't work for me.
The issue definitely relates to Laptops with extended displays.
A solution I stumbled across, in Excel 2016... is, within an Excel Sheet, put an ActiveX Image control behind your Listbox (or other ActiveX control, e.g. command button).
Then change the Z-ORDER of the Image control and "send to back" - so your main control, e.g. Listbox is visible again.
Finally, GROUP the Image control, together with the problematic control, e.g. Listbox.
回答2:
If you have multiple monitors, open your display settings and make sure that the scaling between the 2 is the same. ActiveX list box do not seem to scale properly between monitors of different scaling which causes weird behavior. They will look good on your main monitor but might act smaller/bigger/blurry on your other monitors.
回答3:
I'm always facing the same issue when plugging/unplugging additional monitors to my laptop. It has something to do with the screen(s) resolution and apparently can not be easily fixed with the code.
The solution that works for me is to restart the computer after each time the additional monitor is plugged/unplugged. Then the listboxes work fine again and font size stays the same.
However if you saved the Workbook with the smaller font and it is still small after reopening it, just manually resize the Listbox window (ex. set it a little bit bigger) and then go back to the original size.
来源:https://stackoverflow.com/questions/28638479/strange-activex-listbox-behavior-in-excel