excel - 从用户表单返回一个值
问题描述
我正在尝试将用户窗体中的值返回到另一个宏。
这是我要返回值的一段代码示例intMonth
:
sub comparison()
UserForm1.Show
end sub
然后我有用户表单代码:
Private Sub initialize()
OptionButton1 = False
End Sub
Private Sub OptionButton1_Click()
intMonth = 1
Me.Hide
End Sub
如何将intMonth
值1
恢复到原始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
推荐阅读
- c# - Oracle打开连接在其他计算机上不起作用
- javascript - JavaScript 代码未在对话窗口中执行
- kotlin - 如何从 json 构造我的 Kotlin API 类?(使用 Moshi)
- c# - 处理更新详细记录的 RESTful 方式
- javascript - Vanilla Javascript 和 XML - For-loop 问题
- wordpress - 仍然找不到硬编码的清单开始网址?
- mysql - MySQL-滥用聚合函数
- c++ - Why does keyword struct in C++ differ from keyword struct in C?
- php - 限制周末使用优惠券
- xargs - 使用 fswatch 和 xargs 更改 /var/www/html 文件夹的权限和所有者