This is interesting because I never knew that you could have two modules declaring a public type with the same name. Now that I know, I'm terrified.
So Eric Towers is correct that you want to place a Type declaration in only one module. Other modules that use this type will depend on whether this module is available, but this is just something that comes with modulation. The need to manage dependencies between modules is common to all software development. Unfortunately, in a single VBA project (such as you'll find in one Excel workbook), the only option for managing module dependencies is a guide. (In VBA, “modules” are indeed “source code files.” Other languages / environments have different higher-level packaging systems.)
Now for the horrific part. If you declare types with the same name in different modules, you are setting yourself up for problems. Consider two VBA modules:
'Module1 Public Type typ x As String End Type Public Sub useTyp() Dim t As typ tx = 42 Debug.Print tx + tx End Sub
and
'Module2 Public Type typ x As Long End Type Public Sub useTyp() Dim t As typ tx = 42 Debug.Print tx + tx End Sub
in the same project, your code will "compile" (at least in Excel VBA). But the two useTyp subsystems give different results. Even worse, if you delete one of the type declarations from one of the modules, you suddenly change the behavior of the "useTyp" routine in the same module! Such ambiguity is never desirable.
What happens, VBA does create two different types: Module1.typ and Module2.typ. When you are in the same module and do not qualify the type name, VBA silently finds the "correct" type and uses it.
I'm a little surprised to hear that you pass instances of one "XYpointType" to modules that have another "XYpointType" declaration. It's not that important, but can you post the code? I am interested in such ridiculous things ...
source share