Local variables are available only in the procedure where they are declared : Variable Scope « Language Basics « VBA / Excel / Access / Word






Local variables are available only in the procedure where they are declared

 
Private Sub cmdOkay_Click()
  Dim strAnimal As String
  strAnimal = "Dog"
  Call ChangeAnimal
  Debug.Print strAnimal 'Still Dog
End Sub

Private Sub ChangeAnimal()
  strAnimal = "Cat"
End Sub

 








Related examples in the same category

1.Local variable
2.Procedure-Level (Local) Variables
3.module-level variable declared with Private statement
4.Understanding Module-Level Variables
5.Public Variables
6.Understanding and Using Static Variables
7.sub module scope
8.Module level variable
9.Private module variable