Excel, Compile VBAProject - change the compilation order of modules

Suppose we are in the Visual Basic editor in Excel 2007. We create one module called modGlass :

 Sub VolatileGlass() Dim Glass As shiny_surface End Sub 

and then create a second module called modMetal :

 Sub durableMetal() Dim metal As metal_compound End Sub 

enter image description here

Subscribers in both modules contain an error: "User-defined type not defined."

When I compile a project using the Debug: Compile VBAProject menu command, the modGlass module modGlass always compiled first. If I:

  • double click on modMetal module and compile (is this?) or
  • rename modMetal to amodMetal (so that the metal module is the first in the tree hierarchy of the project module)

The modGlass module modGlass compiled first.

Question: if I have a project with several modules in VBE, is there a way to indicate in which sequence the modules will be compiled?

I don't need this feature, but I'm just wondering if it has a quick way to do this. I am using Excel 2007.

+4
source share
1 answer

Modules are not compiled based on their names, but in the sequence in which they were created. So it doesn’t matter if you put "a" before modMetal

To verify this, create two modules. Make sure both modules have errors. When you compile it, you will notice that the created module will be compiled first. Now remove the 1st module and recreate it. This time, when you compile it, the second (but not created) compiles first :)

No, unfortunately, there is no direct path (AFAIK) to indicate this sequence. However, the dirty way to do this is based on what I suggested above. Copy all the data into notepad, and then delete all the modules, and then recreate them from scratch (in the order in which you want to compile them).

NTN

+4
source

All Articles