如何在AA单独的模块中使用vba的subroutine调用用户形式的子例程
我想知道如何调用位于两个选项按钮的用户形式中的公共子例程。具体来说,如果从该用户选择该用户选择BUTTON1如果选择了该用户,请从模块中的子例程中运行一些代码。
在用户形式代码中:
Public Sub OptionButton1_Click()
Optionbutton1 = True
Optionbutton2 = False
End Sub
Public Sub OptionButton2_Click()
Optionbutton1 = False
Optionbutton2 = True
End Sub
Public Sub TextBox1_Change()
End Sub
在模块中:
Global Optionbutton1 As Integer
Global Optionbutton2 As Integer
-------------------------------------------------------------
Sub ProjectSetup(Optionbutton1. Optionbutton2)
Call UserForm1.OptionButton1_Click
Call UserForm1.OptionButton2_Click
If OptionButton1 = True then
[do some action]
If OptionButton2 = True then
[do some action]
我认为我的问题是基于我尝试在子例程中调用“ optionbutton1_click”和“ optionbutton2_click”的方式。当我运行上面的代码时,我会收到一个编译错误,该错误指示功能或未定义的子。
感谢您的帮助!
I am wondering how I can call a public subroutine that resides within a userform of two option buttons. Specifically if that user selections optionbutton1 from that userform is selected, then run some code from a sub routine within a module.
In the UserForm code:
Public Sub OptionButton1_Click()
Optionbutton1 = True
Optionbutton2 = False
End Sub
Public Sub OptionButton2_Click()
Optionbutton1 = False
Optionbutton2 = True
End Sub
Public Sub TextBox1_Change()
End Sub
In Module:
Global Optionbutton1 As Integer
Global Optionbutton2 As Integer
-------------------------------------------------------------
Sub ProjectSetup(Optionbutton1. Optionbutton2)
Call UserForm1.OptionButton1_Click
Call UserForm1.OptionButton2_Click
If OptionButton1 = True then
[do some action]
If OptionButton2 = True then
[do some action]
I think my issue is based on how I am trying to call in the subroutines "OptionButton1_Click" and "OptionButton2_Click" from UserForm1. When I run the code above I get a compiling error that states the function or sub not defined.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是 做您正在做的任何事情的正确方法,但这会起作用。
在
userform1
中:在常规模块中:
This is not the right way to do whatever it is you're doing, but this would work.
In
UserForm1
:In a regular module: