Excel Macros For Dummies. Dick KusleikaЧитать онлайн книгу.
the Editor tab of the Options dialog box. Use the option in the Editor tab to control how certain things work in the VBE.
FIGURE 2-4: The Editor tab in the Options dialog box.
The Auto Syntax Check option
The Auto Syntax Check setting determines whether the VBE opens a dialog box if it discovers a syntax error while you’re entering your VBA code. The dialog box tells roughly what the problem is. If you don’t choose this setting, VBE flags syntax errors by displaying them in a different color (red by default) from the rest of the code, and you don’t have to deal with any onscreen dialog boxes.
The Require Variable Declaration option
If the Require Variable Declaration option is set, VBE inserts the following statements at the beginning of each new VBA module you insert:
Option Explicit
Changing this setting affects only new modules, not existing modules. If this statement appears in your module, you must explicitly define each variable you use. Using a Dim statement is one way to declare variables.
If you don't set this option, VBA won't require you to explicitly declare your variables. If you don't declare a variable, VBA will declare it for you the first you use it. That is, VBA will create a spot in memory with that variable's name. That may seem like a time saver, but the first time you mistype a variable, you'll be glad you required variable declaration. Bugs from misspelled variables can be hard to find.
The Auto List Members option
If the Auto List Members option is set, VBE provides some help when you’re entering your VBA code. It displays a list that would logically complete the statement you’re typing. This feature is very useful for saving time while coding.
The Auto Quick Info option
If the Auto Quick Info option is selected, VBE displays information about functions and their arguments as you type. This is similar to the way Excel lists the arguments for a function as you start typing a new formula.
The Auto Data Tips option
If the Auto Data Tips option is set, VBE displays the value of the variable over which your cursor is placed when you’re debugging code. This is turned on by default and often quite useful. There is no reason to turn this option off.
The Auto Indent setting
The Auto Indent setting determines whether VBE automatically indents each new line of code the same as the previous line. Most Excel developers are keen on using indentations in their code, so this option is typically kept on.
By the way, you should use the Tab key to indent your code, not the spacebar. Also, you can use Shift+Tab to “unindent” a line of code. If you want to indent more than just one line, select all lines you want to indent and then press the Tab key.
To show the VBE’s Edit toolbar, right-click any toolbar and select Edit from the context menu. It contains two useful buttons: Indent and Outdent. These buttons let you quickly indent or “unindent” a block of code. Select the code and click one of these buttons to change the block’s indenting.
The Drag-and-Drop Text Editing option
The Drag-and-Drop Text Editing option, when enabled, lets you copy and move text by dragging and dropping with your mouse.
The Default to Full Module View option
The Default to Full Module View option sets the default state for new modules. (It doesn’t affect existing modules.) If set, procedures in the Code pane appear as a single scrollable list. If this option is turned off, you can see only one procedure at a time.
The Procedure Separator option
When the Procedure Separator option is turned on, separator bars appear between each procedure in a Code pane. Separator bars provide a nice visual line between procedures, making it easy to see where one piece of code ends and where another starts.
The Editor Format tab
Figure 2-5 shows the Editor Format tab of the Options dialog box. With this tab, you can customize the way the VBE looks.
FIGURE 2-5: Change the way VBE’s looks with the Editor Format tab.
The Code Colors option
The Code Colors option lets you set the text color and background color displayed for various elements of VBA code. This is largely a matter of personal preference.Some Excel developers stick with the default colors. But if you like to change things up, you can play around with these settings.
The Font option
The Font option lets you select the font that’s used in your VBA modules. For best results, stick with a fixed-width font such as Courier New. In a fixed-width font, all characters are exactly the same width. This makes your code more readable because the characters are nicely aligned vertically and you can easily distinguish multiple spaces (which is sometimes useful).
The Size setting
The Size setting specifies the point size of the font in the VBA modules. This setting is a matter of personal preference determined by your video display resolution and how good your eyesight is.
The Margin Indicator Bar option
This option controls the display of the vertical margin indicator bar in your modules. You should keep this turned on; otherwise, you won’t be able to see the helpful graphical indicators when you’re debugging your code.
The General tab
Figure 2-6 shows the options available under the General tab in the Options dialog box. In almost every case, the default settings are just fine.
The most important setting on the General tab is Error Trapping. If you are just starting your Excel macro writing career, it’s best to leave the Error Trapping set to Break on Unhandled Errors. If Excel encounters an error, it stops executing, highlights the line that caused the error, and gives you a chance to figure out what went wrong.
FIGURE 2-6: The General tab of the Options dialog box.
The Docking tab
Figure 2-7 shows the Docking tab. These options determine how the various windows in the VBE behave. When a window is docked,