vba中的userform和主模块之间的交换值
我已经在这个问题上工作了好几个小时,所以我会很感激任何答案。
我有一个用户窗体有三个button,我喜欢他们传递一个值,所以我可以在我的主要模块中使用该值,并根据值,运行特定的代码。 我到处search,但他们都从文本框传递值
这是我的用户表单代码:
private sub cancelButton_Click() response = 1 UserForm1.Hide End Sub private Sub SutunButton_Click() response = 2 UserForm1.Hide End Sub private Sub TirButton_Click() response = 3 UserForm1.Hide End Sub
这是我的主要模块:
public response as integer sub example() . . . userform1.show if response=1 then msgbox "1" elseif response = 2 then msgbox "2" elseif response = 3 then msgbox "3" end if . . . end sub
当然,我把msgbox
使我的代码简单。
谢谢你的帮助
删除全局。 给模块添加:
Public Sub process(form As UserForm1, response As Integer) form.Hide Select Case response Case 1: MsgBox 1 Case 2: MsgBox 2 Case 3: MsgBox 3 End Select End Sub
将事件更改为:
private Sub SutunButton_Click() process Me, 2 End Sub