top of page

Sometimes, it's just the little things - #7: Are you still typing Debug.Print?!

John

Updated: 3 days ago

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.


When testing and debugging code, I used to get really fed up with typing Debug.Print again and again. I say "used to" because I haven't typed Debug.Print into the VBE for some considerable time now.


Using the AutoText functionality of VBE_Extras, you can just type a "?" then press Tab, Return or Enter (which you use depends on the selection you have made in the 'AutoText' tab of VBE_Extras 'Settings' dialog ... you also need to enable 'Debug.Print from ?'), and the hard work is done for you.


AutoText - Debug.Print

A single ? on a line by itself is turned into just Debug.Print on a line by itself. Not that exciting.


However, as you can see from the above, if the ? follows the name of a variable it will not only add Debug.Print but also includes the name of the variable (or anything else) in the Debug.Print statement so that the name as well as the value is sent to the Immediate window.


If the value type of the variable is String, then the Debug.Print line will include escaped speech marks around the value ... this is so that if the String starts or ends with whitespace, then that is obvious in what is sent to the Immediate window.


And if the value type of the variable is an object type (i.e. not "As Object" but a specific type of object ... Workbook in the above example), then you will be shown a list of the object's members for you to select which one you want to send to the Immediate window (see the video above for an example for a variable with a Workbook value type ... note that this functionality also works if you are using Special Binding). Same if the value type is a user-defined Type.


You can also type multiple variable names with the last one being followed by a ? and VBE_Extras will include all of them in a single Debug.Print statement.


Finally, it doesn't have to be a variable preceding the ?. It can be anything that has a value type ... could be a Function (so long as it doesn't have any arguments, or only has Optional or ParamArray arguments), Property Get, Type element etc.


Oh, and if you hold down the Shift key while pressing Tab, Enter or Return (after the ?) then you will get Now thrown in for a timestamp of when the Debug.Print line is run.


Saves me keystrokes. Makes me smile.

Commentaires


bottom of page