【发布时间】:2020-01-30 04:29:11
【问题描述】:
我有 2 个用户表单。在 userform1 中,选择要打开的工作表和一些文本框。在 Userform2 中,有额外的选项框和一个命令按钮来卸载 Userform2 和激活工作表 1,但它不会加载...我曾经能够运行它,直到我添加了一个代码来提示用户完成字段..不是确定我的代码有什么问题,它不会再继续打开工作表了
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
Userform2 代码:
*'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
【问题讨论】:
-
消息框不工作时是否显示?
-
UserForm1.Sheet1.Value看起来很可疑。也许应该是OptionBox#之一? -
嗨,nathan,我认为是因为 Userform1 卸载并且 userform2 打开
-
您卸载了 userform1,但随后您尝试从 userform2 访问它 - 也许只是隐藏 userform1?
-
Sheet1是 UserForm1 上的控件吗?鉴于这是工作表的默认代号,这有点令人困惑......