top of page

Introducing the Code Navigator

3 hours ago
4 min read

The VBE's Project Explorer shows you Projects and their Modules ... and stops there. To see what is inside a Module, you open it and scroll, or pick from the two drop-downs at the top of the code pane, one Module at a time.


The Code Navigator, new in VBE_Extras 1.8.0.0, does much more. It is a window that shows a "tree" of every open Project: each Project; its Modules; the members of those Modules; and the children of those members ... and it stays open beside your code while you work.


The Code Navigator docked beside the code pane in the VBA editor

If you have used the Code Explorer, the tree will look familiar, because the two share it. The difference is that you open the Code Explorer, use it and close it again, whereas the Code Navigator is a dockable window, like the VBE's own Project Explorer, that you can keep open all the time. And, unlike the Code Explorer, the Code Navigator can be refreshed (or will refresh itself) to keep aligned with your code.


This is the first of three posts about the Code Navigator. This one covers what it shows and how to get around with it.


Showing the Code Navigator


To show or hide it, select VBE_Extras > View > Code Navigator. Drag it against an edge of the VBE to dock it, or leave it floating, just as you can with the VBE's own windows. The VBE remembers where it was docked and what size it was, and VBE_Extras remembers whether it was showing, so it is there again the next time you open the VBE.


If you would rather not go through the menu, as with all VBE_Extras commands, you can also add it to the VBE_Extras toolbar, give it a keyboard shortcut (in the Shortcut Keys tab of the Settings), or find it with Command search.


The tree


  • The top level has one node for each open Project, in the same order as the Project Explorer, in bold

  • Below each Project are its Modules (in groups, or not ... your choice) and, if you switch them on, its Project References and CCAs (Conditional Compilation Arguments)

  • Below each Module are its declarations including: procedures, properties, Enums, Types, Windows API "declares" and, for UserForms and Document Modules (including Forms and Reports in Access), Controls

  • And below each of those, where appropriate, are any further child declarations: parameters, variables, constants, statics, Enum members, Type elements etc


Every type of declaration has its own icon, and a Class Module that is used as an Interface (IExporter in the image below) has a different icon from the other Class Modules.


The Code Navigator's tree showing Enums, Types, properties, an event, an Interface and a UserForm's Controls

Where there is more to say about a node, hovering over it shows a tooltip ... for a Project, for example, how many of its Modules do not have Option Explicit. If you see an amber "!" after a name, there is something you should know about that node: hover over it to find out what.


Getting around


  • Double-click a declaration that has no child declarations and it is shown in the code pane. Double-click anything else and it expands or collapses. If you want a double-click to always go to the declaration, check "Go to on double-click" in the Options (the "+" and "-" keys still expand and collapse)

  • Enter goes to the declaration or Module in the code pane, whatever the "Go to on double-click" option is set to. On a node with nowhere to go to (a Project or a group), it expands or collapses it

  • Right-click a node for the commands that apply to it: Copy Name, Copy Declaration, View Declaration, Go to Declaration, View all References and Rename, plus (where they apply) view Project Stats, View Attributes, View as text file, Make 'Option Explicit' and more

  • VBE_Extras keyboard shortcuts work while the focus is in the tree too


The Code Navigator's right-click menu for a declaration

Where am I? Locate, and 'Show in Code Navigator'


You will often want to go the other way: from the code you are working on to its place in the tree. There are two ways:


  • The Locate button (an icon with two magnifying glasses) in the Code Navigator's toolbar selects the node for whatever you are working on: the declaration the cursor is in, the Control that is selected in a UserForm designer, or the Module etc.

  • Show in Code Navigator is on the right-click menus of the code pane, the Project Explorer and the UserForm designer. It shows the Code Navigator (if it is hidden), refreshes it if it is out of date, selects the right node, and moves the keyboard focus to the appropriate node in the tree. You can give it a keyboard shortcut in the Shortcut Keys tab of the Settings (the shortcut does what the Locate button does) and / or add it to the main VBE_Extras toolbar.


Using 'Show in Code Navigator' from the code pane

The Code Navigator's toolbar


The buttons at the top of the Code Navigator are shown with icons only ... hover over one to see what it does:


  • Refresh - brings the tree up to date (more on that in the next post)

  • Options - what the tree shows and how the Code Navigator behaves

  • Locate - selects the node for whatever you are working on (see Where am I? Locate, and 'Show in Code Navigator')

  • Collapse - collapses the tree one level at a time, until only the Projects are left


Try it


The Code Navigator is in VBE_Extras from release 1.8.0.0. It needs a VBE_Extras licence or, like all VBE_Extras functionality, it is included in the free trial. If you are not yet a VBE_Extras user, head to the VBE_Extras page to try it for free. To learn more, see the "Code Navigator" chapter of the user guide.


There are two more posts about the Code Navigator to come: how it keeps itself up to date as you work, and how to make it your Project Explorer.

Comments


bottom of page