You have probably opened the VB Editor in Access, Word, or PowerPoint, and seen Option Explicit at the top of the code window. But what does it mean?
Option Explicit means that you must declare all variables before using it anywhere in your code. Some variables are declared directly underneath Option Explicit, while others are declared within a procedure. Regardless, you should declare them! And using Option Explicit will make sure that you do. By using it, it will help trap undeclared or misspelled variables. That way, you can immediately correct the error before you proceed to the next line of code.
Here are the steps to ensure explicit declaration in Microsoft Office 2007:
- In the VB Editor, choose Tools -> Options, and make sure you are on the Editor tab.
- Under Code Settings, check Require Variable Declaration.
- Click OK.
Easy enough, right? The only downside is that this new setting will only trap undeclared variables in new projects, not old ones.
To hear about the latest Office 2010 news, blogs, and training, subscribe to our newsletter. Click here to subscribe.