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
- 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.