Visual Basic global variables in Excel Macro

邮差的信 提交于 2020-01-05 12:35:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!