Excel: the Incredible Shrinking and Expanding Controls

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

    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,

    • Button A - The size of the button would shrink on the MouseDown event
    • Button B - The text would enlarge on the MouseMove event (But only after the button was clicked. AKA, I click a button, code executes, leave the mouse hovering over the button, and then as soon as I move the mouse the text would enlarge)
    • Text input box A - The text would enlarge on the MouseUp event
    • Text input box B - The text would enlarge on the LostFocus event

    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):

    • Size tab: Lock aspect ratio box is checked
    • Properties tab: Print Object box is unchecked

    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

提交回复
热议问题