无法从用户窗体读取按钮单击的值
我希望这是一个相对简单的问题,尽管我花了几个小时在网上搜索并使用 T&E 但没有成功。希望有人可以提供帮助;o)
我有一个 Excel 模块,它显示一个用户窗体,用于在进行大量处理之前获取一些输入数据。用户窗体的底部有几个标记为“确定”和“取消”的命令按钮。我需要能够让用户更改选项按钮,然后单击“确定”或“取消”退出,我的模块将根据以下内容继续该过程无论是否按下“取消”,我似乎都找不到通过按下表单上的“取消”按钮来读取布尔结果的方法,我 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
根据“取消”的 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 的帮助!
I hope this is a relatively easy problem although I have spent hours websearching and using T&E to no avail. Hopefully someone can help ;o)
I have an excel module that shows a UserForm to get some input data before doing a lot of processing. At the bottom of the userform are a couple of command buttons labeled "OK" and Cancel". I need to be able to have the user change option buttons then click on OK or Cancel to exit, where my module will continue the process based on whether or not "Cancel" was pressed. I just can't seem to find a way to read a Boolean result from pressing the Cancel button on the form. I'm 99% sure it's some kind of Public / Private referencing error, but I haven't earned enough experience to figure it out yet. Here is the code snippets:
(From Module1)
Sub ModuleName()
Dim State as Boolean
' Display Parameter box
UserForm2.Show
If UserForm2.ButtonCancel Then
State = True
Else
State = False
End If
End Sub
Based on the True or False from the Cancel, I can drive the rest of the procedure.
(UserForm2 Code)
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
That's it. It looks like it should be simple but I'm stumped. TIA for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[已解决]
我终于想通了。我只需要在 Module1 的声明部分中使用此语句:
Public BtnCancel As Boolean
[SOLVED]
I finally figured ti out. I just needed this statement in the Declarations Section of Module1:
Public BtnCancel As Boolean