几乎每当我使用用户窗体时,它都会缩小,几次后它变得太小而看不到,因此我必须回到项目的窗体中并将其拖动到大小再次变大。这是我的代码的结果,还是我可以解决此问题?
Option Explicit
' called on click of "OK" button
Private Sub CommandButton1_Click()
MyFile = Me.ComboBox1.Value
Unload Me
End Sub
' called on click of "Cancel" button
Private Sub CommandButton2_Click()
Stopped = True
Unload Me
End Sub
' loads the combo box with the names of all available workbooks
Private Sub UserForm_Initialize()
Dim wkb As Workbook
With Me.ComboBox1
For Each wkb In Application.Workbooks
If wkb.Name <> ActiveWorkbook.Name Then
.AddItem wkb.Name
End If
Next wkb
End With
End Sub
答案 0 :(得分:1)
我想不出发生这种情况的原因,尤其是没有任何代码在任何地方调整表单的Height
和Width
以及表单Unload
本身每次显示该表单时,即使您Show
-使用表单的默认实例,它也应该仍使用设计时值进行初始化。
您可以尝试在该初始化处理程序中明确强制使用大小:
Private Sub UserForm_Initialize()
Me.Height = 480
Me.Width = 600
InitializeComponents
End Sub
Private Sub InitializeComponents()
PopulateAvailableInactiveWorkbooks
'...
End Sub
Private Sub PopulateAvailableInactiveWorkbooks()
Dim wkb As Workbook
With Me.ComboBox1
For Each wkb In Application.Workbooks
If wkb.Name <> ActiveWorkbook.Name Then
.AddItem wkb.Name
End If
Next wkb
End With
End Sub