Results 1 to 7 of 7

What does Option Explicit mean and do?

This is a discussion on What does Option Explicit mean and do? within the Excel Questions forums, part of the Question Forums category; Can anyone help explain what does Option Explicit means and what does it do in a macro? (kinda redundant, I ...

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    357

    Default

    Can anyone help explain what does Option Explicit means and what does it do in a macro? (kinda redundant, I know, since the topic is self-explanatory)

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339

    Default

    From the VBA help files, explains it quite neatly really and should always be your first port of call: -

    Used at module level to force explicit declaration of all variables in that module.

    Syntax

    Option Explicit

    Remarks

    If used, the Option Explicit statement must appear in a module before any procedures.

    When Option Explicit appears in a module, you must explicitly declare all variables using the Dim, Private, Public, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time.

    If you don't use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.

    Note Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    357

    Default

    Sorry about that. But my computer at work doesn't have the VBA help files installed. And I am not sure if the IT people would want me to install it.

    Is there an online source where I can look all of this up?

  4. #4
    MrExcel MVP Joe Was's Avatar
    Join Date
    Feb 2002
    Location
    Central Florida, USA
    Posts
    7,539

    Default

    It forces variable definitions. This helps when you use variables to hold and insert or exchange data or controls with in code. This form allows for a clear scope of use when variable usage is complicated or could become unclear. Its use also helps keep frequently used variables from being miss-typed. Helps keep variables from being assigned a variant type if not defined with a Def statement. The down side is it can only be used in a true module.

    The skinny on it is: It forces explicit variable declaration. Hope this helps. JSW

  5. #5
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339

    Default

    Oh, no, I wasn't having a go at you . It was meant just as a tip as the help files are very useful. I don't see why IT wouldn't let you have them, they should be there after a standard Excel/ Office install anyway.

  6. #6
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530

    Default

    It would probably be easier to go and ask your IT people to install it or install it yourself if your system does that "install on first use" thingy.

    If they say "no" demand a reason. If the reason is insufficient give them so many lefts that they'll be begging for a right.

    Verbal abuse doesn't seem to have much effect on IT people (ours have built up a tolerance to it), stick to the violence.

    HTH

  7. #7
    Board Regular
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    357

    Default

    MudFace,
    Don''t worry about it. I just was apologizing for not being able to find things on my own and bothering gooe people like you and the others who have responded to this with a question, I should be able to answer on my own.

    Anyway,
    Here's a link I found that might be useful.

    http://msdn.microsoft.com/library/de...hanges2000.asp

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com