VBE_Extras adds a whole load of functionality (see What is VBE_Extras) to the standard VBE. But sometimes, rather than the major areas of functionality, it's just the little things that it does that make me smile. Here's an example.
In each VBA Project, you can add Conditional Compilation Arguments (in the Project Properties dialog, General tab). Here's an example with two Conditional Compilation Arguments (CCAs), CCA_ONE has a value of 42 and CCA_TWO has a value of 43.

These CCAs are then Project-level ... you can access them from any Module within your VBA Project (whereas those defined using the #Const directive are Module-level and Private ... they can only be accessed in the Module in which they are declared).
VBE_Extras is 'conditional compilation aware'. That is, it knows which lines in each of the Modules within your Project are compiled-in and which are compiled-out. Here's a basic example using the Highlighting command of VBE_Extras ... note that Highlighting normally highlights a declaration and its associated references in a solid box, but if the declaration or reference is compiled-out then it highlights it in an empty box, as you can see below:

Now, this is great ... except for the fact that VBE_Extras reads the value for SOME_CONST from the text of the Module (i.e. it searches your code for the #Const directive that declares SOME_CONST and reads it's value). But this doesn't work for CCAs declared in the Project Properties dialog ... while the VBE itself, and your VBA code, knows about the CCAs in the Project Properties dialog box, VBE_Extras doesn't automatically do so (as they are not stored in your code).
VBE_Extras has had a solution for this for some time. Actually two solutions ... in the VBE_Extras main menu, select Conditional Compilation Arguments then:
To manually enter the names and values of the CCAs, select 'Update CCAs for this Project manually' ... just like it says, you can then manually enter the names and values of the CCAs
To automatically let VBE_Extras read the names and values of the CCAs, select 'Update CCAs for this Project automatically' ... VBE_Extras will then read the names and values directly from the Project Properties dialog
... having done this, all VBE_Extras functionality will then be aware of these CCAs and their values. This is fine until you close the VBA Project ... because, when the Project closes, then VBE_Extras loses any 'knowledge' of that Project including the names and values of any CCAs. Or it did.
As of release 1.5.4.0, VBE_Extras will store (when you close your VBA Project) and restore (when you re-open your VBA Project) the names and values of the CCAs. This is functionality that you need to switch on (it isn't on by default) which you do in the 'Other' tab of the Settings dialog ... select 'Store / restore Conditional Compilation Arguments'.
This functionality works across multiple Projects ... it doesn't just store / restore CCAs for the last Project you had opened, but for all Projects (and they are stored per-Project ... CCAs for one Project do not 'interfere' with CCAs for another). Additionally, if you switch on 'Restore when a Project is unlocked' (in the same tab of the Settings dialog) then it will also restore CCAs when a Project is unlocked (i.e. when password protection is removed).
Just for clarity, it isn't just the highlighting commands of VBE_Extras that are 'conditional compilation aware', all commands that relate to finding and updating declarations and references are 'conditional compilation aware'.
Now, I know that using Project-level CCAs is a bit 'niche'. I reckon less than 1% of people who write VBA code have ever used them. I reckon many (most?) readers of this post won't even know they exist. But they do ... and they can be really useful if you need to use the same conditional compilation across multiple Modules. I would guess the most frequent use-case for this is for early/late binding when the library that you are using is used across multiple Modules.
Anyway, I do use them. Not often, but I do. And not having to manually, or automatically, update them every time I open a VBA Project make me smile!
p.s. 1 - if you change the values (or names) of the CCAs in the Project Properties dialog and you want VBE_Extras to be aware of the new names/values, you will still have to update them for VBE_Extras (either manually or automatically as noted above).
p.s. 2 - if you are using conditional compilation to control early / late binding, whether across 1 Module or multiple Modules, you might want to check out special binding and eliminate the need for conditional compilation at all!
p.s. 3 - if you want to read more about conditional compilation in VBA, see the Directives page of the VBA language reference and to read more on the Project Properties dialog and entering CCAs, see the Project Properties dialog box page of the VBA language reference.
Comments