Declaring global variables in your VBA application can facilitate the sharing of information among different code modules. In a VBA code module, variables can have different scopes, such as procedure-level, module-level, and global-level. The declaration for each variable is different, depending on its scope. Variables should always be defined with the smallest scope possible to avoid adding complexity to the code. Define your global variables in one module only to quickly get to them when you need to. Public myGlobalVar As String Public Sub defineVal() myGlobalVar = “this is a global variable” End Sub Private Sub showGlobalVar() End Sub Writer Bio
