Option Explicit - To use or not.

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
319
Office Version
  1. 365
Platform
  1. Windows
Hi all, I've been working on a new workbook for my wife to record her sales and expenses throughout the year. The VBA elements are pretty basic and ultimately the workbook is only going to be used by her.

I've been doing the final testing on all the forms and code to tidy it all up and remove any test code used whilst building it and just noticed I have missed off Option Explicit on most of the modules, question is do I really need to use it as the code all works fine without it.

I know why is used and may just add it in as I go through the various modules anyway but just wanted to get your thoughts on using it or not.

Thanks Paul
 
To anyone new to VBA:
Use Option Explicit, in fact, set that as default.

1. Weakly typed languages have a place, but VBA won't ever be updated again, it comes as is. Bugs and everything.
2. You WILL find issues without Option Explicit and they will be easy to solve once you turn on Option Explicit.
3. When you encounter an issue that has something to do with types, and trust me, you WILL, you want to have control over that, you do not want to let the compiler choose for you. The guys who made VBA are not perfect, their software has bugs and VBA won't be updated to fix those bugs.
4. Declaring your types does not necessarily mean declaring everything at the top, you can declare your variables when you need them to avoid having orphan variables later or forgetting what their type was.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,215,110
Messages
6,123,138
Members
449,098
Latest member
Doanvanhieu

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