Ans : Variable is special value or storage location in computer memory which hold the value for later use.
⚝ We can declare Variable using Dim,Static,Private,Public KeywordFor Ex :
Public FileName As String
Private Age As Long
Dim XlFile As Variant
Dim MobileNo As Double
Dim OlApp As Object
⚝ Also We Can Declare Variable for Workbook as below :
Dim Wks As Worksheet
Dim WB As WorkBook
Dim Rng As Range
⚝ Rules For Declaration :
1) It must be less than 255 characters
2) No spacing is allowed
3) It must not begin with a number
4) Period is not permitted
Q ) Difference Between Dim,Private,Public,Global Variable
Ans :
☞ Dim and Private work the same, though the common
convention is to use Private at the module level,
and Dim at the Sub/Function level.
☞ Public and Global are nearly identical in their function,
however Global can only be used in standard modules,
whereas Public can be used in all contexts (modules, classes,
controls, forms etc.)
☞ Global comes from older versions of VB and was likely
kept for backwards compatibility, but has been wholly
superseded by Public.
☞ VBA Global Variables are variables which are declared
before the start of any macro in the module.
☞ When the variables are declared by using either
"Public" or "Global," it becomes "Global Variable."
convention is to use Private at the module level,
and Dim at the Sub/Function level.
☞ Public and Global are nearly identical in their function,
however Global can only be used in standard modules,
whereas Public can be used in all contexts (modules, classes,
controls, forms etc.)
☞ Global comes from older versions of VB and was likely
kept for backwards compatibility, but has been wholly
superseded by Public.
☞ VBA Global Variables are variables which are declared
before the start of any macro in the module.
☞ When the variables are declared by using either
"Public" or "Global," it becomes "Global Variable."
Tags:
Variable