Excel: the Incredible Shrinking and Expanding Controls

前端 未结 30 1925
予麋鹿
予麋鹿 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:21

    This problem is very frustrating, my experience is that the properties are usually set properly on the ActiveX objects. I've modified a UDF from above to just be able to run on any active sheet, this will set everything back the way it was before shrinking.

    Public Sub ResizeAllOfIt()
    Dim myCtrl As OLEObject
    
    For Each myCtrl In ActiveSheet.OLEObjects
    
     Dim originalHeight
     Dim originalWidth
    
     originalWidth = myCtrl.width
     originalHeight = myCtrl.height
    
      myCtrl.height = originalHeight - 1 
      myCtrl.height = originalHeight 
      myCtrl.width = originalWidth
    
    Next myCtrl
    
    End Sub
    
    0 讨论(0)
  • 2020-11-28 05:22

    [EXCEL PROFESSIONAL PLUS 2016, 32BITS, VERSION 1802, BUILD 9029.2167]

    I was having the same issue and I could solve the problem by customizing the display scaling in windows 10, 64 bits. It is extremelly simple and it works for a single user. Just follow the instructions below and you will have all the Form Controls, sheet shapes, figures and ActiveX Controls back to their original size. No need to coding or doing advanced trickery/wizardry/hacks. If the provided link is broken, just repeat these steps.

    1. To Set Display Custom Scaling in Windows 10, you need to do the following.

      Open Settings.

    2. Go to Settings - Display.
    3. On the left, click the Custom Scaling link under "Scale and Layout".
    4. The Custom Layout page will be opened. Specify a new value for scaling percent. [USE 100] !! ... and voilá. Close and re-open Excel.

    It is an old post, but I hope it helps anyone who is dealing with this annoying and stressing Excel problem.

    https://winaero.com/blog/set-display-custom-scaling-windows-10/

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

    After searching the net, it seams the best solution is saving the file as .xlsb (binary) rather than .xlsm

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

    What I started doing a while back was to have a single sub that sets the size of all my controls. I can then run this sub from any point in the code where the controls grow or shrink. It's sometimes a lot of extra finicky work, but it keeps my buttons from eating my spreadsheet.

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

    Could it be that the button is defined to stick to the corners of a cell, instead of floating freely ?

    Check it with

    Format | Properties | Object Positioning

    and choose anything but "move and size with cells"

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

    We just solved this on a company level by adding the following module to all macro enabled workbooks:

    Option Explicit
    
    Type ButtonSizeType
        topPosition As Single
        leftPosition As Single
        height As Single
        width As Single
    End Type
    
    Public myButton As ButtonSizeType
    
    Sub GetButtonSize(cb As MSForms.CommandButton)
    ' Save original button size to solve windows bug that changes the button size to
    ' adjust to screen resolution, when not in native resolution mode of screen
        myButton.topPosition = cb.top
        myButton.leftPosition = cb.Left
        myButton.height = cb.height
        myButton.width = cb.width
    End Sub
    
    Sub SetButtonSize(cb As MSForms.CommandButton)
    ' Restore original button size to solve windows bug that changes the button size to
    ' adjust to screen resolution, when not in native resolution mode of screen
        cb.top = myButton.topPosition
        cb.Left = myButton.leftPosition
        cb.height = myButton.height
        cb.width = myButton.width
    End Sub
    

    Just call them in the beginning and end of your code like this:

    Private Sub CommandButton1_Click()
    
    Application.ScreenUpdating = False
    ' Turn off ScreenUpdating to make sure the user dosn't see the buttons flicker
    GetButtonSize CommandButton1 ' Saves original button size
    ' Do cool things
    '
    '
    '
    SetButtonSize CommandButton1 ' Restores original button size
    
    Application.ScreenUpdating = True
    ' Turn ScreenUpdating back on when you're done
    End Sub
    
    0 讨论(0)
提交回复
热议问题