Tip Why go to the trouble Option Explicit helps the compiler catch any variable names you may have mistyped It also helps you avoid confusion when the scope of a variable may not be clear

To turn Option Explicit on, do the following:

1. From any Excel workbook, open the VBE.

2. From any open workbook, choose the Visual Basic command from the Code tab of the Developer ribbon, or press Alt+F11.

3. In the VBE, choose Tools > Options to display the Options dialog box, as shown in

Figure 7-3.

4. If it's not already checked, in the Code Settings section in the top half of the Options dialog box, click the Require Variable Declaration check box. In Figure 7-3, the arrow cursor points to this item.

Figure 7-3. The VBE's Options dialog box

5. Click OK to save the changes and close the Options dialog box.

Once this is done, any time you create a new code module or open the code module attached to any worksheet, the Option Explicit command will already be inserted at the top of the module.

0 0

Post a comment