Occasionally, I\'ll happen across a spreadsheet which suffers from magic buttons or listboxes which get bigger or smaller over time.
Nothing in the code is instructi
I may have found a fix: "make sure all shapes on the worksheet have unique names" (including checkboxes/radio buttons (OLE controls) as well as Pictures and other shape types...)
Because the problem is intermittent, I can not guarantee this. I have two forms now working fine using this fix, but "two" is a very small sample set, and could just be coincidence. Never the less, these are steps I took:
I listed all shapes in the problem sheet (wsForm) on a blank sheet (Sheet1):
Sub ListShapes()
Dim spShape As Shape
Dim intRow As Integer
Sheet1.Range("A1:F1") = Array("Name", "Left", "Top", "Width", "Height", "Bottom Right Cell")
intRow = 2
For Each spShape In wsForm.Shapes
Sheet1.Cells(intRow, 1).Value = spShape.Name
Sheet1.Cells(intRow, 2).Value = spShape.Left
Sheet1.Cells(intRow, 3).Value = spShape.Top
Sheet1.Cells(intRow, 4).Value = spShape.Width
Sheet1.Cells(intRow, 5).Value = spShape.Height
Sheet1.Cells(intRow, 6).Value = spShape.BottomRightCell.Address
intRow = intRow + 1
Next
End Sub
I then counted each shape name in column A, using a formula in column G:
=COUNTIF($A$2:$A$120,A2)
Obviously adjust range to suit... You can then filter on all shapes that don't have a "1" in this column. The "bottom right cell" helps you find the shape on your worksheet: rename by selecting the shape, then entering new unique value in the name/reference box at top left of Excel.
This shape list also helped find some "dead" shapes (0 height or 0 width) which were long forgotten and unused.
I hope this works for you! For that matter... I hope it works for ME for future occurrences...
I run across this issue all the time in Excel 2010 (Which always brings me back to this thread) and although I haven't found a fix 100%, I believe I have some information that can help others.
While tediously playing around with the buttons I discovered that DIFFERENT EVENTS for each object were causing different issues. For example,
The only solution that works for me is to write code to reset the size/text for each object event that was causing the random resizing. Like so ...
Where MaterialNum is the name of the input box, and MouseDown is the event ...
Private Sub MaterialNum_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
' Reset the size, font style, and size
With Worksheets("QuoteForm").Shapes("MaterialNum")
.Height = 21
.Width = 101.25
.Left = 972.75
.Top = 87
With .DrawingObject.Object.Font
.Name = "Arial"
.Size = 12
End With
End With
End Sub
In addition, I had to change a few options in Format Control (Right click object > Format Control):
Also, in the Object Properties pane (Right click object > Properties) I set TakeFocusOnClick to false
Yes, this is time consuming and tedious as it has to be done with each object, but it's the only fix that works for me (And it seems to be a quicker fix than waiting for Microsoft to fix this!!!). Hopefully it helps others.
I hope others find this helpful
I had the problem also with ActiveX listboxes and found the following elsewhere and it seems to work so far, and it seems also the by far easiest solution that transfer along when handing the spreadsheet to someone else:
"While the ListBox has an IntegralHeight property whose side-effect of a FALSE setting will keep that control from going askew, and while command buttons have properties such as move/size with cells, etc., other controls are not as graceful."
And they have some more advice: http://www.experts-exchange.com/articles/5315/Dealing-with-unintended-Excel-Active-X-resizing-quirks-VBA-code-simulates-self-correction.html
If you wish to not show the button moving back and forth, you can put the original placement into your code then just check against those. Turn off screen updating when button is clicked, check to see if the the placement is different on the control, change it back, if needed, turn screen updating back on
DP
Add this code to a .reg file. Double-click and and confirm. Restart Excel.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\options]
"LegacyAnchorResize"=dword:00000001
[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common\Draw]
"UpdateDeviceInfoForEmf"=dword:00000001
The problem seems to relate to the way Windows handles non-native resolutions on monitors and can be avoided in several ways
The problem can be a complete nightmare when it happens, but it only happens intermittently.
We have been testing recently an excel worksheet used by a few dozen people and have developed a good idea of the cause and some possible fixes.
The cause seems to relate to any setup where screens are used in something other than their native resolution. This can happen easily if a user plugs an external monitor into a laptop and doesn't choose the resulting screen configuration carefully. For example, if a laptop is plugged into a projector (perhaps an old one with a native 1024 by 768 display) but the laptop is a 1280 by 800 and the user chooses to duplicate the display rather than extending it (settings in "connect to a projector" or "displays" control panel in Windows 7), the result is an unpredictable and usually unsatisfactory image on both screens with both in non-native resolutions. We have found that these settings almost always cause serious problems with Excel buttons, especially ActiveX controls. Sometimes, on repeated clicks, they shrink to unreadability; other times they expand to cover the whole screen.
Mostly, when we instruct users to use the extend display setting and the result is two screens both using native resolutions, we don't see the problem.
There are also code-based ways to minimize the problem. We tried resetting the location and size of buttons and controls when they were clicked (which adds a lot of tedious code if you have a lot of buttons). This sometimes worked. We also tried toggling the autosize property from true to false and back (this works manually in developer mode) and this fixes more instances, but not apparently all.