VBA Environment
Unfortunately the default environment settings are not geared towards high quality development, they are set to make it easy for beginners to get productive quickly.
These are our preferred settings for professional quality development (Tools>>Options)
The default is to have those top 2 reversed.
You always get Auto Syntax Check (line goes red), removing the tick stops the disruptive modal error message boxes from constantly popping up every time you move off a line to copy something:
If the advice were a bit more helpful it might be worthwhile, but even beginners would struggle to get any value out of the above example. And it isn't going to get better as VBA is end of lined. Advice: Turn off Auto Syntax Check.
Require Variable Declaration puts an 'Option Explicit' at the top of each new code resource you open (module, class, form etc) (note it is not retrospective, hence the need to set it ASAP). Not using option explicit is just sloppy and is sure to lead to hard to spot errors in any significant coding.
if you want to use a variable called x (you may be able to think of a more meaningful name) OE forces you to 'Dim' it first, and optionally to decide what data type it should be. If OE is missing VB will implicitly Dim the variable as a variant the first time you use it, if you later mistype the variable name VB will create another new variable, rather than warn you 'Variable not defined' which would be more useful.
Note these settings will be reflected in other Office applications. |