我希望这是一个相对简单的问题,尽管我花了数小时进行网络搜索和使用 T&E 无济于事。希望有人可以提供帮助;o)
我有一个 excel 模块,它显示一个 UserForm 在进行大量处理之前获取一些输入数据。在用户窗体的底部有几个标记为“确定”和“取消”的命令按钮。我需要能够让用户更改选项按钮,然后单击确定或取消退出,我的模块将继续基于是否按下了“取消”。我似乎无法通过按下表单上的“取消”按钮来读取布尔结果。我 99% 确定这是某种公共/私人引用错误,但是我还没有获得足够的经验来弄清楚。这是代码片段:
(来自模块 1)
Sub ModuleName()
Dim State as Boolean
' Display Parameter box
UserForm2.Show
If UserForm2.ButtonCancel Then
State = True
Else
State = False
End If
End Sub
根据 Cancel 中的 True 或 False,我可以驱动程序的其余部分。
(UserForm2 代码)
Private Sub ButtonCancel_Click()
BtnCancel = True
Unload Me
End Sub
Private Sub ButtonOK_Click()
BtnCancel = False
Unload Me
End Sub
Private Sub ButtonReset_Click()
'Set the Default Settings
NEAlias.Value = "True"
NoteIgnore.Value = "True"
ABIgnore.Value = "True"
LinkIgnore.Value = "True"
End Sub
Private Sub UserForm_Initialize()
Dim BtnCancel As Boolean
'Add the Text to the options
NEIgnore.Caption = "Ignore"
NoteIgnore.Caption = "Ignore"
ABIgnore.Caption = "Ignore"
LinkIgnore.Caption = "Ignore"
NEAlias.Caption = "Alias Only"
NoteAlias.Caption = "Alias Only"
ABAlias.Caption = "Alias Only"
LinkAlias.Caption = "Alias Only"
NEMove.Caption = "Move and Alias"
NoteMove.Caption = "Move and Alias"
ABMove.Caption = "Move and Alias"
LinkMove.Caption = "Move and Alias"
'Set the Default Settings
NEAlias.Value = "True"
NoteIgnore.Value = "True"
ABIgnore.Value = "True"
LinkIgnore.Value = "True"
End Sub
而已。看起来应该很简单,但我很难过。TIA 寻求帮助!