Trainers' thoughts on Microsoft Office products

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.

No TweetBacks yet. (Be the first to Tweet this post)

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 [...]

Tweetbacks

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | UK: 0808-101-3484 | From outside the USA: 315-849-2724 | Fax: 315-849-2723