Project Level Variables

Module-level variables that are declared with the Public keyword (instead of Dim) have project-level scope. This means that they can be used in any Visual Basic for Applications module. When you want to work with a variable in all the procedures in all the open VBA projects, you must declare it with the Public keyword. For instance:

Option Explicit

Public slsTax As Single

Sub CalcCost( )

<place procedure instructions here> End Sub

Notice that the slsTax variable declared at the top of the module with the Public keyword will now be available to any other procedure or VBA project.

0 0

Post a comment