Hidden & little known features in VBA and the VBE (3 Viewers)

isladogs

MVP / VIP
Local time
Today, 09:42
Joined
Jan 14, 2017
Messages
19,111
Prompted by an old thread at Stackoverflow, I thought it might be interesting for members to share features that are not widely known in VBA.
Here's a couple to get started. If the thread gains traction, I may add some more ....

1. Adding Option Private Module in the declarations section is used at module level to indicate that the entire module is private.
This means module-level parts not declared Private are available to other modules in the project, but not to other projects or applications.

This has another benefit in that it can be used to fully hide details of constants, variables and procedures in an ACCDE file.
When an ACCDE file is created, the module code is no longer available to view or edit.

However, a lot of information can still be seen in ACCDE files including a list of procedures and values of any constants that have been defined.
To prevent this, you can add the line Option Private Module to any standard or class module.

For more details, see https://www.isladogs.co.uk/vbe-option-statements/

2. Pressing Ctrl+T whilst in the VBE brings up an archaic Components dialog. Its in all versions of Access though apparently of little use.

1755327867626.png


Which little known / little used features of VBA would others like to share?
 
1. Get the value and type of anything that is currently running by using the debugger:
You don't even have to know the name of what you're looking for, everything is there for you to explore and start using right away, even undocumented stuff (a lot of stuff is undocumented). Avoid those pesky Debug.Print statements that you later have to remove or comment out.

How:
- Open the VBE Editor
- Go to the View menu and choose Watch Window.
- Right click the window and choose Add Watch
- Write application in the input box
- Select All modules and All procedures as context
1755332961957.png

- Need to see what an open form looks like? Expand Application, then find the Forms collection and choose your target
1755333115945.png

- You'll get something like this:
1755333179519.png

- Need to see a control in that form? You can find those at the end of the Form object or in the Controls collection, just choose your target:
1755333320931.png

- Need to see a custom collection? load it there, some variable? load it there. Just make sure to select the right context. Most times you just have to drag the variable from your code and drop it there.

This applies to the whole Office suite, you can do this in Excel, PowerPoint, Word, etc.
 

Users who are viewing this thread

Back
Top Bottom