PDA

View Full Version : A neat timesaver for Immediate ("debug") Window - abbreviations



TheAntiGates
08-30-2017, 09:18 AM
There are millions of "tips" out there but this one is, I believe, extremely obscure, and possibly has never been used or publicized, so I'm confident that you would be the first on your block with this one.

It involves employing abbreviations - or you might want to sloppily use the term "aliases" - for objects, to reduce tedious typing or pasting in the Immediate Window. During development I spend mucho hours in the Immediate window (and watch window and shift-F9, etc.) so this can pay off. However, if you don't often type anything into the Immediate Window, read no further, as this won't benefit you. But if you likes to go fast fast, despite the Microsoft Deproductivity Team's fervent efforts to slow Excel users (cough! Ribbon! cough! Jensen! cough!), here it is:

Instead of
?activewindow.caption, activewindow.zoom, activewindow.top
you can instead go
set a=activewindow:?a.caption, a.zoom, a.top

Instead of
?sheets("BababouieDentalData").rows.count, sheets("BababouieDentalData").displaypagebreaks, sheets("BababouieDentalData").protectContents
go
set s=sheets("BababouieDentalData"):?s.rows.count, s.displaypagebreaks, s.protectContents

You can also stack 'em up:
set a=activewindow:set s=sheets("BababouieDentalData"):?a.this, s.that, a.somethingelse, ...

I only showed examples with 3 "debug.print" terms; sometimes I'll do 6 or 8 in real life.

Obviously you can instead of all this just type an object name once and highlight it and go shift-F9 and enter (creating a Watch item) and scroll and expand and read across to get the info you need. Sometimes that's the way to go. However often it's much quicker just to do everything in the Immediate window.

Also flyovers often quickly give you an answer, or when that's unavailable, highlighting something and going shift-F9 gets you quick answers with little or no typing. So this technique is not something to do all the time.

Of course if you're facile with writing scratch code, you can do your "aliasing" or create temporary With statements there, such that all you might have to do is type
debug.print .caption, .zoom, .top
but sometimes I don't want to write and police scratch code - I just want quick answers in the Immediate window.

Another major benefit of abbreviating is that you can generally more efficiently/accurately visually process a long hairy statement in the compact form a.this, s.that.

I'll mention another huge timesaver, Control-J to bring up an autocompletion dropdown - for many things: user variables, properties, etc. I note this here because it is the one drawback I've seen to this "set" abbreviation technique. If you type a and a dot you don't get the sweet dropdown that you get from typing activewindow and a dot.

Finally, syntactically you are allowed to go
With activewindow:?activewindow.caption, activewindow.zoom, activewindow.top:End With
but alas, it will not accept
With activewindow:?.caption, .zoom, .top:End With
so the with statements don't seem to be useful. Perhaps someone will discover otherwise.

Technical note: I don't know if there's leakage or garbage collection involved here, or if appending :set a=nothing is an appropriate measure.

There's are tips-a-plenty out there but this one seemed obscure enough that I thought I'd pass it on.

SamT
08-30-2017, 10:31 AM
Thanks.
Nice to see you're still kickin', its been a while.

Aflatoon
09-01-2017, 07:40 AM
but alas, it will not accept
With activewindow:?.caption, .zoom, .top:End With
so the with statements don't seem to be useful. Perhaps someone will discover otherwise.


Separate lines in the immediate window can't be related to each other, so a With block can't work. That's why you can't use an If ... Then...End If construct, or nest separate clauses. You can use an If ... Then with multiple instruction lines for each part and no End If, but there is no single line equivalent for a With block.