This post may contain affiliate links. Please read my disclosure for more info.
Advertisement:

1.6 Setting up the Visual Basic Editor environment

Beginning VBA

Beginning VBA

Previous Part: 1.5 Adding comments

As part of this course (and hopefully ongoing) you will be spending a lot of time in the Visual Basic Editor.  So, let’s get it set up so that it provides the tools and options we need.  I won’t go into why each tool is important, but trust me it will make your life easier much easier.

 

Displaying the Edit Toolbar

The Edit Toolbar contains some of the most useful tools in the VBE.  But, for some reason, it is not enabled automatically.  To enable this Toolbar click View -> Toolbars -> Edit.

VBA Editor Edit Toolbar Turn On

Once enabled you should see the additional tools.  They may appear in a floating window initially, but you can drag this into the menu at the top of the VBE and they will be added to that area.  In the screenshot below I have placed them above the coding window.


Advertisement:

VBA Editor Edit Toolbar Display

The simplest tools to use (and the tools I use the most) are:

  1. Code indenting tool – you can select an entire block of code and press these buttons, the code will be indented or de-indented as an entire block.  This is really useful when adding loops or if functions around big blocks of existing code.
  2. Add/Remove comment tool – you can select entire blocks of code and comment out the code.  This is useful where you do not want to delete the code, but you don’t want to execute when you next run the code either.

 

Turn off Auto Syntax Check

Auto Syntax Check displays, in my opinion, unnecessary errors messages.  We will still be able to see the errors, but we will not get an annoying error message popping up.

To turn off the Auto Syntax Check click Tools -> Options …

VBA Editor Options

From the Options Window, de-select Auto Syntax Check, as shown by [1] in the window below.


Advertisement:

VBA Editor Options Window

Click OK to accept the changes.

 

Forcing variables to be declared

We will discuss variables in a future section.  But for now, we are just setting up the VBE environment, so check to ensure that Require Variable Declaration is enabled. Follow the same instructions as the section above, but ensure that [2] highlighted in the section above has been enabled.

 

Using the Immediate Window

The Immediate Window is the place where we can see messages as our VBA code is executed.  It may not seem that useful now, but when it comes to debugging and checking the logic flow of your code it is essential.


Advertisement:

To turn on this feature click View -> Immediate Window (or Ctrl+G as the shortcut)

VBA Editor Immediate Window Turn On

This will open the Immediate Window below the coding window.

VBA Editor Immediate Window Example

Your coding environment is ready

It may not seem like these are big changes, and you may not use these features straight away, but you have made significant steps to making your VBA coding life much less frustrating.

 

Previous Part: 1.5 Adding comments

Next Part: 2.0 First steps in programming VBA