我对ListBoxes使用以下内容.按钮的原理相同; 适当适应.
Private Sub myButton_Click()
Dim lb As MSForms.ListBox
Set lb = Sheet1.myListBox
Dim oldSize As ListBoxSizeType
oldSize = GetListBoxSize(lb)
' Do stuff that makes listbox misbehave and change size.
' Now restore the original size:
SetListBoxSize lb, oldSize
End Sub
Run Code Online (Sandbox Code Playgroud)
这使用以下类型和过程:
Type ListBoxSizeType
height As Single
width As Single
End Type
Function GetListBoxSize(lb As MSForms.ListBox) As ListBoxSizeType
GetListBoxSize.height = lb.height
GetListBoxSize.width = lb.width
End Function
Sub SetListBoxSize(lb As MSForms.ListBox, lbs As ListBoxSizeType)
lb.height = lbs.height
lb.width = lbs.width
End Sub
Run Code Online (Sandbox Code Playgroud)
小智 6
我在最后添加了一些代码onClick:
CommandButton1.Width = 150
CommandButton1.Height = 33
CommandButton1.Font.Size = 11
Run Code Online (Sandbox Code Playgroud)
似乎工作。
我以稍微不同的方式解决了这个问题。通过在我的主要笔记本电脑显示器上打开工作簿,然后将其移动到我的大显示器上。我会假设相同的根本原因。
小智 5
在 Excel 2007、2010 和 2013 中看到此问题
此代码可防止问题显现。每次激活活动 X 对象时都需要运行代码。
Sub Shared_ObjectReset()
Dim MyShapes As OLEObjects
Dim ObjectSelected As OLEObject
Dim ObjectSelected_Height As Double
Dim ObjectSelected_Top As Double
Dim ObjectSelected_Left As Double
Dim ObjectSelected_Width As Double
Dim ObjectSelected_FontSize As Single
ActiveWindow.Zoom = 100
'OLE Programmatic Identifiers for Commandbuttons = Forms.CommandButton.1
Set MyShapes = ActiveSheet.OLEObjects
For Each ObjectSelected In MyShapes
'Remove this line if fixing active object other than buttons
If ObjectSelected.progID = "Forms.CommandButton.1" Then
ObjectSelected_Height = ObjectSelected.Height
ObjectSelected_Top = ObjectSelected.Top
ObjectSelected_Left = ObjectSelected.Left
ObjectSelected_Width = ObjectSelected.Width
ObjectSelected_FontSize = ObjectSelected.Object.FontSize
ObjectSelected.Placement = 3
ObjectSelected.Height = ObjectSelected_Height + 1
ObjectSelected.Top = ObjectSelected_Top + 1
ObjectSelected.Left = ObjectSelected_Left + 1
ObjectSelected.Width = ObjectSelected_Width + 1
ObjectSelected.Object.FontSize = ObjectSelected_FontSize + 1
ObjectSelected.Height = ObjectSelected_Height
ObjectSelected.Top = ObjectSelected_Top
ObjectSelected.Left = ObjectSelected_Left
ObjectSelected.Width = ObjectSelected_Width
ObjectSelected.Object.FontSize = ObjectSelected_FontSize
End If
Next
End Sub
Run Code Online (Sandbox Code Playgroud)