After some frustration, the following code helped me get around this Excel / VBA error. Pay attention to two key things:
- Although others have recommended resizing and then immediately resizing it immediately, note that this code does not allow you to resize it more than once when changing one switching state. If the value changes twice during one change in the state of the event (especially if the second value matches the initial value), the alternative width and height properties may never be applied to the control, which will not reset the width and height of the control as it should for prevent reduction in width and height.
- I used hard-coded width and height values. This is not ideal, but I found that this was the only way to prevent the control from being compressed after a few taps.
Private Sub ToggleButton1_Click ()
'Note: initial height is 133.8 and initial width was 41.4
If ToggleButton1.Value = True Then
'[Code that I want to run when user clicks control and toggle state is true (not related to this issue)]
'When toggle value is true, simply change the width and height values โโto a specific value other than their initial values.
ToggleButton1.Height = 40.4
ToggleButton1.Width = 132.8
Else
'[Code that I want to run when user clicks control and toggle state false (not related to this issue)]
'When toggle value is false adjust to an alternate width and height values.
'These can be the same as the initial values, as long as they are in a separate conditional statement.
ToggleButton1.Height = 41.4
ToggleButton1.Width = 133.8
End if
End sub
For a control that doesn't switch, you can use an iterator variable or some other method to ensure that the width and height properties alternate between two identical sets of values, resulting in an effect similar to the switching state changes I used in this case.
adamlane Jul 02 '19 at 22:46 2019-07-02 22:46
source share