我正在尝试将值从用户窗体返回到另一个宏。
下面是我想要返回值 intMonth
的一段代码示例:
sub comparison()
UserForm1.Show
end sub
然后我有用户表单代码:
Private Sub initialize()
OptionButton1 = False
End Sub
Private Sub OptionButton1_Click()
intMonth = 1
Me.Hide
End Sub
如何将 1
的 intMonth
值返回到原来的 comparison()
函数?
最佳答案
这是一个最小的示例,但应该有所帮助。
在用户表单中:
Option Explicit
Option Base 0
Public intMonth As Long ' <-- the variable that will hold your output
Private Sub initialize()
OptionButton1 = False
intMonth = 0
End Sub
Private Sub CommandButton1_Click() ' OK button
Me.Hide
End Sub
Private Sub OptionButton1_Click()
intMonth = 1 '<-- set the value corresponding to the selected radio button
End Sub
Private Sub OptionButton2_Click()
intMonth = 2
End Sub
在模块或ThisWorkbook
中:
Option Explicit
Option Base 0
Sub comparison()
UserForm1.Show
MsgBox CStr(UserForm1.intMonth) ' <-- retrieve the value
End Sub
关于excel - 从用户表单返回一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51952304/