Global Level (Public)

Also known as Global Variables or Project Level.
A public module level variable is declared in the declarations section of a code module and is visible to all modules in the project.
Global level variables can have two flavours either Public or Global.
If you declare a variable at the top of a module with the Private statement it is not global level, its module level.

Public g_sProjectLevel As String 
Global g_sProjectLevel As String

You must insert these statements at the very top of your modules, before any procedures or functions.
A public variable at the top of a module can be used outside that module.


Public or Global ?

Declaring as Global is exactly the same as Public and is only included for backwards compatibility.

Global g_sProjectLevel As String 
Public g_sProjectLevel As String

Public Sub Procedure_Name()
End Sub

Always use Public for Global Level variables.


Inside Userforms

Global level variables must also be declared in a standard code module and not is a userform or class module.
Declaring a variable as Public inside a userform does not make it public.
It is still private and only visible to that userform code module only.


link - docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/public-statement


© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext