Who uses Option Explicit?

Do You Use Option Explicit When You Write VBA Code?

  • I'm an advanced VBA user and I use Option Explicit

    Votes: 29 45.3%
  • I'm an intermediate VBA user and I use Option Explicit

    Votes: 22 34.4%
  • I'm a new VBA user and I use Option Explicit

    Votes: 3 4.7%
  • I'm an advanced VBA user and I do not use Option Explicit

    Votes: 1 1.6%
  • I'm an intermediate VBA user and I do not use Option Explicit

    Votes: 5 7.8%
  • I'm a new VBA user and I do not use Option Explicit

    Votes: 1 1.6%
  • What the heck are you talking about?

    Votes: 3 4.7%

  • Total voters
    64

Fazza

MrExcel MVP
Joined
May 17, 2006
Messages
9,200
Option explicit should be the default; I don't know why it isn't.
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,786
Office Version
365
Platform
Windows
I use Option Explicit all the time. I'm such a graet tpyist that it's worth my while...
Also, once I set the capitalisation in the variable I always type in lower case after that. Helps catch typos...

Denis
And I thought I was being smart! Unfortunately same doesn't work for UDTs, typing in lower converts the type name and all previous references to it to lower case! Grrr!

I hope plenty more participate in the poll. It would be nice to see the stats with a larger sample. Especially like that you have separated advanced, intermediate and new users in the sample, because I have often wondered how many accomplished programmers actually don't force explicit declaration.
 
Last edited:

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Using Option Explicit all the time and to complete the variable names without typos using Ctrl+Spacebar

example
type this
Code:
Dim tzhkzjthkjghdlkfgjfhdslgkjdshg As Single 'or whatever
tz
then Ctrl+Spacebar and you'll get the variable at once

kind regards,
Erik
 

gardnertoo

Well-known Member
Joined
Jul 24, 2007
Messages
938
I voted Intermediate - No. I know I should use OE, I just forget to. I'll try to do better, I promise!
 

Smitty

MrExcel MVP
Joined
May 15, 2003
Messages
29,536
Just go into the VBE tools and check it. That way you won't need to worry about forgetting. ;)
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,392
Office Version
365
Platform
Windows
I've got it turned on in all applications where I use VBA.

Mind you I do find myself deleting it quite a lot when all I want to do is some quick testing.

How about compiling?

Do many people just run the code before using Debug>Compile Project?

One handy thing I noticed recently after installing 2010 was that once I'd set Option Explicit on in Excel it was reflected elsewhere.

I thought I'd end up having to set it in each application as I went.

How about IntelliSense?

It's normally pretty handy, for things like completing variable names as Erik pointed out, but I find sometimes I end up declaring Longs as LoadPictureConstants etc..:)
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,555
Office Version
2016
Platform
Windows
I have the Option Explicit set by default but I tend to temporarly remove it if I am doing some quick testing of code that contains API callbacks to avoid cheerful GPFs.:)
 

Sandeep Warrier

Board Regularmmmm Pizza
Joined
Oct 31, 2008
Messages
2,672
I'm relatively used to always declaring variables (xept for when I'm too lazy :)) ... never thought of using Option Explicit .... programmed a bit in C while in college

When I started VBA, I had some accidental "non-declarations" by using

Dim XYZ, ABC, DEF As Integer..... because I thought this would consider all the variables as integers ... cuz I was used to

Int a, b, c etc.... in C :)
 

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
I've got it turned on in all applications where I use VBA.
How about compiling?

Do many people just run the code before using Debug>Compile Project?
That'd be me... I compile once I've made lots of changes, and before setting up the next version of a database on a client machine. Probably should do it more often

One handy thing I noticed recently after installing 2010 was that once I'd set Option Explicit on in Excel it was reflected elsewhere.

I thought I'd end up having to set it in each application as I went.
Haven't used 2010 enough to come across that yet, but I like the idea.

How about IntelliSense?

It's normally pretty handy, for things like completing variable names as Erik pointed out, but I find sometimes I end up declaring Longs as LoadPictureConstants etc..:)
Yeah, you get some weird datatype declarations with Intelli(non)sense but on the whole I find it useful enough to keep it enabled. I like Erik's shortcut though.

Denis
 

yytsunamiyy

Well-known Member
Joined
Mar 17, 2008
Messages
963
Voted intermediate-always. Just as Denis said - I'm too bad a typist not to rely on the capitalisation trick, and I had a few nasty surprises with undeclared variables. Variant data type doesn't always give you what you'd expect to get. :)
 

Forum statistics

Threads
1,084,878
Messages
5,380,415
Members
401,673
Latest member
Ali Balleya

Some videos you may like

This Week's Hot Topics

Top