Excel 整个应用程序消失(在后台运行),而不是打开工作表;第1页“;在VBA中

Excel 整个应用程序消失(在后台运行),而不是打开工作表;第1页“;在VBA中,excel,vba,Excel,Vba,我有两个用户表单。在userform1中,要打开的工作表与一些文本框一起被选中。在Userform2中,有额外的选项框和命令按钮来卸载Userform2并激活工作表1,但它不会加载…我以前可以运行它,直到我添加了提示用户完成字段的代码。不确定我的代码有什么问题,它将不再继续操作工作表 Userform1代码: Userform2代码: 一旦你卸载UseForm1,它就不再可以从UserForm2访问-你应该隐藏UserForm1,直到你完成它,然后卸载它。当它不工作时,消息框会显示吗?嗨,nat

我有两个用户表单。在userform1中,要打开的工作表与一些文本框一起被选中。在Userform2中,有额外的选项框和命令按钮来卸载Userform2并激活工作表1,但它不会加载…我以前可以运行它,直到我添加了提示用户完成字段的代码。不确定我的代码有什么问题,它将不再继续操作工作表

Userform1代码:

Userform2代码:


一旦你卸载UseForm1,它就不再可以从UserForm2访问-你应该
隐藏
UserForm1,直到你完成它,然后
卸载
它。

当它不工作时,消息框会显示吗?嗨,nathan,我这么认为是因为Userform1卸载,userform2打开你卸载Userform1,然后你尝试从userform2访问它-也许只是隐藏Userform1?Sheet1是Userform1上的控件吗?这有点令人困惑,因为这是工作表的默认代码名。。。以及它的陷阱。
Private Sub CommandButton1_Click()

If TextBox1.Value = "" Then
MsgBox "Pls. enter data"
Cancel = True
Exit Sub
End If

If Sheet1.Value = True Then
Unload UserForm1
UserForm2.Show
*'to prompt user to complete fields*
Private Sub CommandButton1_Click()
If OptionBox1.Value = False And OptionBox2.Value = False Then
MsgBox "Pls. select option"
Cancel = True
Exit Sub
End If

*'to open worksheet "Sheet1"*
If UserForm1.Sheet1.Value = True Then
Worksheets("Sheet1").Activate
Application.Visible = True
Unload UserForm2
End If
End Sub