【发布时间】:2020-03-10 15:30:33
【问题描述】:
您好,我的程序有问题。 我正在尝试从我的 UserForm1 打开 UserForm2,但我需要在显示之前为 UserForm2 初始化一些代码。
我在我的代码中使用了UserForm2.Show 并通过Show UserForm2 从 UserForm1 打开它这工作正常,但关闭时它给我错误 91。
我试图删除 UserForm2.Show 但这导致 UserForm2 没有加载并给我错误 13。
这是我的代码
模块1:
Option Explicit
Public ListName As String
用户窗体1:
Private Sub CommandButton1_Click()
If CheckBox5.Value = False And CheckBox6.Value = False Then
MsgBox ("Nebyla zvolena operace.")
GoTo Ukoncit
End If
If CheckBox1.Value = False And CheckBox2.Value = False And CheckBox3.Value = False And CheckBox4.Value = False Then
MsgBox ("Nebyl zvolen list.")
GoTo Ukoncit
End If
If CheckBox5.Value = True Then
End If
If CheckBox6.Value = True Then
If CheckBox1.Value = True Then
ListName = "SAP_CZ"
ElseIf CheckBox2.Value = True Then
ListName = "SAP_CH"
ElseIf CheckBox3.Value = True Then
ListName = "Datab_1"
ElseIf CheckBox4.Value = True Then
ListName = "Datab_2"
End If
Show UserForm2 ' <------------- Here is Opening UserForm2
End If
Ukoncit:
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox4.Enabled = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
If CheckBox1.Value = False Then
CheckBox2.Enabled = True
CheckBox3.Enabled = True
CheckBox4.Enabled = True
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
CheckBox1.Enabled = False
CheckBox3.Enabled = False
CheckBox4.Enabled = False
CheckBox1.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
If CheckBox2.Value = False Then
CheckBox1.Enabled = True
CheckBox3.Enabled = True
CheckBox4.Enabled = True
CheckBox1.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
End Sub
Private Sub CheckBox3_Click()
If CheckBox3.Value = True Then
CheckBox2.Enabled = False
CheckBox1.Enabled = False
CheckBox4.Enabled = False
CheckBox2.Value = False
CheckBox1.Value = False
CheckBox4.Value = False
End If
If CheckBox3.Value = False Then
CheckBox2.Enabled = True
CheckBox1.Enabled = True
CheckBox4.Enabled = True
CheckBox2.Value = False
CheckBox1.Value = False
CheckBox4.Value = False
End If
End Sub
Private Sub CheckBox4_Click()
If CheckBox4.Value = True Then
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox1.Enabled = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox1.Value = False
End If
If CheckBox4.Value = False Then
CheckBox2.Enabled = True
CheckBox3.Enabled = True
CheckBox1.Enabled = True
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox1.Value = False
End If
End Sub
Private Sub CheckBox5_Click()
If CheckBox5.Value = True Then
CheckBox6.Enabled = False
CheckBox6.Value = False
End If
If CheckBox5.Value = False Then
CheckBox6.Enabled = True
CheckBox6.Value = False
End If
End Sub
Private Sub CheckBox6_Click()
If CheckBox6.Value = True Then
CheckBox5.Enabled = False
CheckBox5.Value = False
End If
If CheckBox6.Value = False Then
CheckBox5.Enabled = True
CheckBox5.Value = False
End If
End Sub
UserForm2 给出错误 91:
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim Label1String As String
Label1String = "Chcete opravdu smazat data z listu " & ListName
UserForm2.Label1.Caption = Label1String
UserForm2.Show
End Sub
UserForm2 给出错误 13:
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim Label1String As String
Label1String = "Chcete opravdu smazat data z listu " & ListName
UserForm2.Label1.Caption = Label1String
End Sub
【问题讨论】:
-
我建议你给this article 看看为什么
Unload Me和UserForm2.Show不是一个好主意。
标签: excel vba runtime-error userform