AutoText - numeric and String expansions
- John
- 3 days ago
- 2 min read
The AutoText functionality of VBE_Extras already provided numerous ways to speed up entering code ... now it has one more trick up its sleeve: numeric and String expansions.
These (sort of ...) mimic what is possible in a number of other languages than VBA. For example, in C# (which VBE_Extras itself is developed in), if you have a numeric variable named someNum then ...
someNum++ means "increment someNum by 1"
someNum-- means "decrement someNum by 1"
someNum+=10 means "increment someNum by 10"
someNum-=10 means "decrement someNum by 10"
In C#, these are actually part of the language.
Of course, VBE_Extras cannot add these features directly to the VBA language (VBE_Extras only adds functionality to the VBE ... the VBA code editor ... it doesn't add features to the VBA language itself).
However, what it can do is allow you to enter such text and then expand it to be executable VBA code. So ...
someNum++ expands to someNum = someNum + 1
someNum-- expands to someNum = someNum - 1
someNum+= expands to someNum = someNum +
someNum-= expands to someNum = someNum +
and likewise for variables followed by *=, /=, \=, ^= and, for Strings, &=

For numeric and String expansions to work, it must be enabled in the VBE_Extras settings ... in the VBE menu: Extras > Settings then, in the AutoText tab, ensure "AutoText is active" is checked and then the sub-setting "++, --, +=, -=, *=, /=, \=, ^=, &=" is also checked.
Numeric and String expansions don't only work for variables but also for Statics, Type elements, Functions (within the body of the Function) and Property Gets (again, within the body of the Property Get).



Excellent feature! Probably the thing I've missed most in VBA. Thank you