Webucator blogs about online learning and training.

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:

  1. In the VB Editor, choose Tools -> Options, and make sure you are on the Editor tab.
  2. Under Code Settings, check Require Variable Declaration.
  3. 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.

One Response to “Option Explicit in VBA”

  1. [...] your variables? No. Should you declare your variables? YES! Read more about declaring variables and using Option Explicit in VBA. « Outlining in Microsoft Word 2007 Trackbackno comments [...]


© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | Outside the USA: 315-849-2724 | Fax: 315-849-2723