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
Option explicit should be the default; I don't know why it isn't.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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:
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
 
I voted Intermediate - No. I know I should use OE, I just forget to. I'll try to do better, I promise!
 
Just go into the VBE tools and check it. That way you won't need to worry about forgetting. ;)
 
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..:)
 
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.:)
 
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 :)
 
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
 
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,223,768
Messages
6,174,411
Members
452,562
Latest member
Himeshwari

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top