使用模块中UserForm的变量

时间:2015-04-12 11:07:36

标签: excel vba excel-vba

我有一个带有CheckBox的用户表单

Public MyVariable As String
Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
        MyVariable = "ON"
    Else
        MyVariable = "OFF"
    End If
 MsgBox (MyVariable)
 End Sub

这里,变量MyVariable运行良好。 但是,在模块中:

Public MyVariable As String
Sub Calculate()
MsgBox (MyVariable) 'the msgbox is empty!
If MyVariable = "ON" Then
Call Sex
End If
End Sub

变量MyVariable始终为空。

1 个答案:

答案 0 :(得分:1)

Public MyVariable As String从用户窗体移动到模块。然后两个潜艇都能够看到"它