嗨,我的程序有问题。 我正在尝试从UserForm1打开UserForm2,但是在显示之前我需要为UserForm2初始化一些代码。
我在代码中使用了UserForm2.Show
,并通过Show UserForm2
从UserForm1中将其打开。此方法可以正常工作,但关闭时会出现错误91。
我试图删除UserForm2.Show
,但这导致UserForm2无法加载,并给我错误13。
这是我的代码
Module1:
Option Explicit
Public ListName As String
UserForm1:
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
答案 0 :(得分:0)
此错误是由Show UserForm2
应该是
UserForm2.Show
您无需在UserForm_Initialize子目录中包含此
答案 1 :(得分:0)
我通过从“初始化”到“激活”提供该代码来编辑该代码,删除了In main(), 'catch(ExceptionA e){}', caught exception: class ExceptionA
In main(), 'catch(ExceptionB e){}', caught exception: class ExceptionB
并将UserForm1.Show
替换为Unload Me
现在代码在UserForm2中:
Hide
但是仍然在UserForm1行Private Sub CommandButton1_Click()
Hide
End Sub
Private Sub UserForm_Activate()
Dim Label1String As String
Label1String = "Chcete opravdu smazat data z listu " & ListName
UserForm2.Label1.Caption = Label1String
End Sub
中给出运行时错误13。