VBA development environment

 

VBA editor: Tools à Macro à Visual Basic Editor

Editing/Code window

·        Displays VBA code for editing

·        To customize your editor: Tools à Options

Project window

·        Displays loaded objects and their components

·        Standard vs Class module

·        View code vs View object

Properties window

·        Displays properties of loaded objects

Immediate window

·        Displays the output of debugging statements in your code

·        View à Immediate window

·        ? object.property, e.g., application.name

·        debug.print statements

 

Object browser: View à Object browser

 

Compile on demand: Debug à Compile

Disable the Compile on Demand feature: Tools à Options à General tab

 

Debugging

  1. Use “Option Explicit” statement in the General Declarations section of any module
  2. Indicate what type of data is stored in a variable
  3. Name your variables carefully
  4. Give your variables the narrowest scope possible
  5. Use the immediate window to test your module
  6. Use Debug.Print statements to print to the immediate window at runtime
  7. Place a breakpoint in your code for unconditional halt (Press F9 or Debug à Toggle Breakpoint; combine with Debug à Step Into)
  8. Place a watch in your code for conditional halt (Apply “Quick Watch” to a variable or Debug à Add Watch)
  9. Press Ctrl+Break while the code is running
  10. Insert a STOP statement in your code (permanent)