What is meant by OPTION EXPLICIT

     

  • We should always use OPTION EXPLICIT while executing the VBA program
  •  

  • Option explicit should be mention at the top of the MODULE as "Option Explicit"
  •  

  • If we misspell any variable in program option explicit throws error message
  •  

  • Option explicit forces VBA to declare all the variables with DIM Statement
  •  

    In the below mentioned example., we have two variables i,j,. "I" variable declared with DIM statement where as "J" variable not declared. But application executed the program by considering "J" variable against VARIANT data type.

     

    Option Explicit doesn't allow UNDEFINED variable in program, it forces VBA to define all the variable.

     

     

  • Option explicit thrown error message, as variable "J" not declared
  •  

    In how many ways we can mention OPTION EXPLICIT on top

     

  • We can type manually on top of module
  •  

    (or)

     

  • We can add automatically as mentioned below:
  •  

     

    • Open VB Editor
    •  

    • Tools - - - Options
    •  

    • Uncheck "REQUIRE VARIABLE DECLARIATION"

     

     

     

    Click on Below mentioned Image to watch video:

    Download The Workbook