Why? Because X and Y are private to the procedure scopeTest and subroutine sum does not have access to them. When we run the first subroutine, it runs perfectly and prints the sum of X and Y Option Explicitĭim x, y As Integer ' Procedure level variable in VBAīut when you run the subroutine sum, it throws an error that the variable is not declared. ![]() In the below example, we have a subroutine scope test that has variable x and y. If the module is option implicit then they the variable may have not been declared, just used directly. They are usually declared with Dim keyword. The variables that are declared within a subroutine, can be accessed only in that procedure/function. In Excel VBA, we have three types of scope specifiers: ![]() These scope specifiers can be used to set the visibility/scope of a variable in Excel VBA. In all the programming languages, we have variable access specifiers that define from where a defined variable can be accessed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |