top of page
  • John

VBA - highlighting references in the VBE

Updated: May 6

In any modern code development tool, you can highlight (or the development tool will automatically highlight) all on-screen references of a code member (variable names, Function names, Module names etc).


However, the 'vanilla' VBE doesn't support this for VBA code. But with VBE_Extras ... it does.

In the above video, first the Function name and then a series of variable names are highlighted. Firstly using the main VBE_Extras menu. Then using the VBE_Extras toolbar. And finally using the keyboard shortcut allocated to this (F11 by default).


This isn't just a 'pretty trick'. It is intended to assist with code development ... how many times do you search around on the screen for the previous or next (or all) reference of a code member? How many times do you miss a reference?!


Highlighting isn't the only way that VBE_Extras can help you with identifying where all references of a code member are. You can also get a list of all references using the References function (Extras > References for code at cursor, or Shift+F12 by default) from which you can jump to any individual reference, and you can jump directly to the previous or next reference (Extras > Goto > Previous code reference in this Project / Next code reference in this Project, or Ctrl+Shift+PgUp / PgDown by default).


Highlighting (in fact all of the 'reference' and 'declaration' functions in VBE_Extras) don't just rely on simple name-matching, they are 'scope and context aware'. In other words, if you declare multiple members with the same name in a manner that is compliant with the rules of the VBA language (for example, a Sub named 'Foo' can contain a variable named 'Foo'; multiple modules can all contain Subs named 'Foo') then VBE_Extras is able to apply the rules of the VBA language to determine which reference(s) of 'Foo' relates to which declaration of 'Foo'.

Please don't write code like 'ThisThing'!


But do try out VBE_Extras.


Update May 2024


VBE_Extras will now highlight more than just the on-screen references of a declaration ... it will highlight (in 'priority order'):

If the cursor is ...

What is highlighted

Highlighting type

Positioned within a declaration or reference (whether it is an 'insertion point' or expanded to one or more characters within the name of the declaration or reference)

All of the matching on-screen declaration(s) and reference(s)

An 'empty box' (unless the declaration or reference is excluded due to conditional compilation in which case it is underlined) around the declaration / references

An insertion point within a 'word' (whether a VBA keyword or not) that is not in a string literal or in a code comment

All of the on-screen matches of that word

A 'solid box' over the 'word'

Expanded to one character that is an opening or closing parenthesis or an opening or closing speech-mark

The matching partner of the parenthesis or speech-mark (if it is on-screen)

A 'solid box' over the parenthesis or speech-mark

Expanded to one or more characters

All of the on-screen matches of that range of character(s)

A 'solid box' over the character(s)


0 comments

Recent Posts

See All

Comments


bottom of page