Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Where goes the undeclared variables in VBA

I try to understand what (and how) does some old VBA code.

I have a Sub, and I have a variable that is not declared in that Sub.

The Option Explicit is set to false.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Should I consider that variable a global one? Didn’t found that info in the VBA docs…

Sub test1()
    x = "test one"
End Sub

Sub test2()
    x = "test2"
    Call test1
    MsgBox (">'" + x + "'<")
End Sub

enter image description here

there is no way to navigate to the definition of an undeclared variable
enter image description here

>Solution :

No, undeclared variables are created local to the method/subroutine. It will be deallocated when you exit the routine. If you reference the same variable name in another routine, it will just create another uninitialized local variable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading