Is scoping broken in VBA?

Viewed 168

Say you have this code in a module called Module1:

Option Explicit

Private Type TSomething
    Foo As Integer
    Bar As Integer
End Type

Public Something As TSomething

In equivalent C# code if you made the Something field public, the code would no longer compile, because of inconsistent accessibility - the type of the field being less accessible than the field itself. Which makes sense.

However in VBA you could have this code in Module2:

Sub DoSomething()
    Module1.Something.Bar = 42
    Debug.Print Module1.Something.Bar
End Sub

And you get IntelliSense while typing it, and it compiles, and it runs, and it outputs 42.

Why? How does it even work, from a COM standpoint? Is it part of the language specs?

1 Answers
Related