Excel: the Incredible Shrinking and Expanding Controls

前端 未结 30 1924
予麋鹿
予麋鹿 2020-11-28 04:51

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

相关标签:
30条回答
  • 2020-11-28 05:24

    I find that the problem only seems to happen when freeze panes is turned on, which will normally be on in most apps as you will place your command buttons etc in a location where they do not scroll out of view.

    The solution that has worked for be is to group the controls but also ensuring that the group extends beyond the freeze panes area. I do this by adding a control outside the freeze panes area, add it into the group but also hide the control so you don't see it.

    0 讨论(0)
  • 2020-11-28 05:24

    I've found a fix that works, and solves the problem for a single user. If you don't want to read my little rant you can skip straight to the solution.

    RANT:

    I've been experiencing this stupid problem since the dinosaurs. In the meantime, Microsoft have had plenty of resources to release countless major updates to the Office suite and yet this problem goes unaddressed. It's absolutely infuriating. I have no reason whatsoever to upgrade when basic stuff like this doesn't work. Surely someone at MS uses ActiveX controls in Excel right on a high-res display, no?

    I didn't experience this issue on my desktop PC, no clue as to why, but on my Surface Pro 4 my ActiveX controls go bananas whenever I click them.

    Today I decided to get to the bottom of this. I searched high and low, tried a every solution proposed on various forums (none of which works by the way). It doesn't matter if the controls are grouped or not, locked or not, hotfix installed or not.

    Yesterday I had another problem with things misbehaving in another app called Traktor (DJ software), where controls would jump around when display scaling was set to a value that was not an exact multiple of 100%. A user found the solution was to edit the compatibility mode for this application. So I did the same for Excel, and it worked! Now my controls stay put, regardless of display resolution and scaling.

    SOLUTION:

    (Ensure Excel is not running)

    1. Locate EXCEL.EXE (on my system this can be found at C:\Program Files\Microsoft Office\Office16\EXCEL.EXE)
    2. Rename "EXCEL.EXE" to "_EXCEL.EXE" (basically change it to something else)
    3. Right-click renamed EXCEL.EXE file, then go to Properties > Compatiblity tab > Settings section
    4. Set Override high DPI scaling behaviour = Enabled, and Scaling performed by = Application
    5. Click OK
    6. Rename to "_EXCEL.EXE" back to "EXCEL.EXE"

    Now Excel will run at its native resolution and ActiveX controls won't go awry. The only downside is that Excel won't respond to screen scaling, so things may look a little smaller than one would like. On my Surface Pro 4 is more than acceptable

    NOTES:

    1) Steps 2 and 6 are required with Excel 2016, because the Properties dialog for EXCEL.EXE does not offer the Compatibility tab. After renaming, the tab becomes available.

    2) This solution only works on a one-user basis. That is, if you send an Excel file containing ActiveX controls to your colleagues, the ActiveX controls won't display correctly on their system unless they change the compatibility mode settings.

    3) After applying this hack, previously corrupted Excel files appear to fix themselves when you open them, with all controls recovering their original intended dimensions.

    Please test and comment, I hope this can help someone, cheers!

    0 讨论(0)
  • 2020-11-28 05:27

    found the cause to be people opening the spreasheet on a machine accessed via Remote Desktop, and there being a difference in screen resolution between local and remote machines. This affects the controls available from the control toolbox, but yet to experience the issue using an old school forms button control, so my unsatisfactory answer is to use that.

    0 讨论(0)
  • 2020-11-28 05:28

    Try changing the zoom setting to 100% using the bottom right hand slider. Fixed it for me on both monitors of different sizes.

    0 讨论(0)
  • 2020-11-28 05:29

    My monitors all appear to be set at native resolutions, which deepens the mystery. However, I have found that doing SOMETHING to the button (moving or resizing) somehow fixes the problem. This routine automates the moving, and then restores the original setting.

    The following code seems to address the problem, at least for buttons.

    Public Sub StablizeButton(oButton As MSForms.CommandButton)
    
        With oButton
    
            ' If True, then temporary distortion is remedied only by clicking somewhere.
            ' If False, then the temporary distortion is remedied merely by moving the mouse pointer away.
            .TakeFocusOnClick = False
            ' For best results:  In the Properties Sheet, initialize to False.
    
            .Left = .Left + 200             ' Move the button 200 units to the right, ...
            .Left = .Left - 200             ' ... and then move it back.
    
        End With
    
    End Sub
    

    Invoke it as follows:

    Private Sub MyButton_Click()
        StablizeButton MyButton
    
        ' Remainder of code.
    End Sub
    
    0 讨论(0)
  • 2020-11-28 05:29

    I have found this problem across all objects (buttons,text boxes,etc). When I print/print preview multiple sheets, all the sheets except for the first in the sequence have moved or resized objects. After much testing, the simplest solution in to page zoom up or down and return to the original setting.

    0 讨论(0)
提交回复
热议问题