Setting explicit declarations for variables

You can set VBA for Excel to so that you are forced to declare all variables explicitly without having to write an Option Explicit line in every program. This can be done either globally (for all modules) or on a module by module basis. To do this, choose Tools > Options from the VBE. You will see the Options dialog box. Click the Editor tab, and tick the Require Variable Declaration box (see Figure 5.1). Notice, that it is unchecked by default. Now, if you do this, you will find an Option Explicit appear for each new module that you create.

Editor Editor Format | General | Docking |

Editor Editor Format | General | Docking |

Code Settings 17 Iftuto Syntax Check]

17 Auto Indent

V Require Variable Declaration 17 Auto List Members

lab Width: |4

(7 Auto Quick Info

17 Auto Data Tips

Window Settings & Drag-and-Drop Text Editing P' Detault to Full Module View V Procedure Separator

Window Settings & Drag-and-Drop Text Editing P' Detault to Full Module View V Procedure Separator

OK Cancel Help

Figure 5.1 Setting the explicit variable declaration requirement

0 0

Post a comment