Module Level (Private)

A module level variable is declared in the declarations section of a code module (standard, class or userform).
Module level variables can have two flavours either Private or Dim.
If you declare a variable at the top of a module with the Public statement it is not module level, its global level.

Private m_sModuleLevel As String 
Dim m_sModuleLevel As String

You must insert these statements at the very top of your modules, before any procedures or functions.
A private variable at the top of a module can only be used in the module it is declared in.
A private variable at the top of a module cannot be used outside that module.


Private or Dim ?

If you declare a module level variable with the Dim statement this is equivalent to using the Private statement.
Using Dim for module level variables causes a lot of confusion and should definitely be avoided.

Private m_sModuleLevel As String 
Dim m_sModuleLevel As String

Public Sub Procedure_Name()
End Sub

Always use Private for Module Level variables.


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

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