Is it possible to have a 'public' variable and 'dim' variable with the same name and use both in the same sub?
1 Answer
The more local variable wins (shadowing).
To access the variable in the global scope you would need to qualify it with its containing module name:
Public Foo As Long
Sub g()
dim Foo As String
...
msgbox Foo
msgbox ModuleName.Foo
5 Comments
CodeCamper
Can't accept the answer for 5 more minutes but as soon as I can you got it, the hierarchy is Public, Private, Dim for scope am I missing anything else?
Alex K.
There is also
Static and Friend although the latter is for class methods onlyRadek
There is also Global that I think is even above Public.
CodeCamper
Is there an MSDN documentation page on Scope, it seems strange that they have documentation for all the functions but not the basics of the language itself.
Cool Blue
For office 2013 the language reference is in the Office 2013 shared section