问题
I writing macro for excel on VB. There is a structure:
Forms
Form1
Modules
Main
In the Form1 I have Button click event
Public Sub CommandButton1_Click()
MsgBox GLOBALVAR 'I need access to GLOBALVAR here
End Sub
In the Main I have procedure Test
Sub Test
GLOBALVAR = "VALUE"
End Sub
How I can implement it? I can't create
Module GlobalVariables
End Module
Due to Excel does not support this construction!
回答1:
Add a
Public MyGlobalVariable as String
in the Module1
and it becomes accessible in your userform
来源:https://stackoverflow.com/questions/25141505/visual-basic-global-variables-in-excel-macro