Software

Five of my favorite tips for working efficiently in the Visual Basic Editor

If you spend much time in the VBE, you'll appreciate any shortcuts that streamline your work. Susan Harkins shares the tricks she finds most useful.

When you add code to an Office application, you do so in the Visual Basic Editor. That's where you'll find all the tools you need to write and manage your code. There are numerous shortcuts and tricks for working in the editor, but here are the five I seem to use the most.

1: Copy quickly

Copying portions of procedures (or entire procedures) is a common task for many developers. You can select the code, right-click the selection, and choose Copy, pretty much the same way you'd copy anything in a Windows application. But you can save a few steps using drag and drop. Select the code you want to copy, hold down the [Ctrl] key, and drag the selection. You can even drag from one module to another. Simply open and restore the modules so they're both visible. Then, drag code from one and drop into the other. You can also use drag and drop to move, rather than copy, code. Hold down the [Alt] key while dragging.

2: Double-click title bars to dock and float

To move a docked window, just double-click its title bar. Doing so toggles the window between the docked and floating state. A quick double-click restores the window to its last docked position.

3: Avoid docking madness

Many tips for redocking a window are a bit awkward. The truth is, there are only two easy steps:

  • Right-click the window and check Dockable (if necessary).
  • Using the title bar, drag the window to the appropriate border.

Here's the secret: The VBE will redock the window when the cursor (the white arrow) -- not the window's border -- touches a border. In addition, when docking, the VBE will stretch the window between opposite borders, either horizontally or vertically. Dock to the left or right border to dock vertically. Dock to the top or bottom borders to dock horizontally. Even if you're heading toward the left border, if the pointer touches the top border first, the VBE will dock the window horizontally.

4: Get the Project Explorer and the Properties Window to play nice

By default, the VBE window docks and stacks the Project Explorer and Properties Window to the left of the container window (with the Project Explorer in the top-left corner and the Properties window in the bottom-left corner). If you undock and move one of them, you might have trouble restacking them. You'll probably try #3, but it won't work -- the VBE will simply dock them both to the same border and position one over the other instead of stacking them.

To restack the windows, redock one of them, if necessary. Then, drag the floating window to the upper-left corner to position the floating window on top. (The position is relative to the docked window's position, but most people seem to prefer the left.) When the cursor -- not the window -- touches the top-center of the docked window, release the mouse. The editor will dock and stack the floating window on top of the currently docked window. To position the floating window at the bottom, drag it down until the cursor touches the bottom-center of the currently docked window.

5: Toggle between windows

If you use the VBE at all, you probably know that you can quickly launch the editor by pressing [Alt] [F11]. What you might not know is that this keyboard shortcut is a toggle between the application window and the editor. Once you're in the editor, press [Alt] [F11] to return to the application.


About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

5 comments
DaveUnger
DaveUnger

I also drag modules between projects to copy across code. Am having trouble with step #1, dragging & dropping between modules - (Simply open and restore the modules so they?re both visible - I don't quite understand this). Appreciated the tips on docking, especially the "white arrow" secret.

Tink!
Tink!

I do use the Alt-F11 to open the editor, but still use Alt-Tab to go back and forth from the editor and the application.

ssharkins
ssharkins

I'm not sure where you're getting lost with the drag and drop tip -- by restore, I'm talking about about the Minimize and Maximize buttons to the right of the title bar. Minimize (restore) but modules and size them so that you can see them both -- that way you can drag from one to the other.

DaveUnger
DaveUnger

Oh, of course! Thanks so much, Susan - for some reason I got "de-railed" while interpreting this. Works perfectly, great tip! I'd just like to add how much I appreciate all your contributions. regards, Dave

ssharkins
ssharkins

Thank you Dave -- I'm glad it's working for you now!