VBA Summary

There are entire books dedicated to VBA, many of them very good. This appendix has only covered some very basic items that might be helpful to someone who has not had much experience with VBA. Most VBA books focus only on the core language and don't give you much help dealing with objects. Having stated that, mastering the VBA language makes your job of performing automation of other applications much easier.

I strongly suggest that when you use VBA, you use Option Explicit at the top of all your modules. This forces you to declare all variables. While some people consider this to be a pain, it ensures that you get an error message if you misspell a variable. I have helped people find errors that took hours to find that would have been found instantly if variable declaration had been required.

The most important thing to keep in mind is that your main goal is to get a job done with VBA. In most cases, inefficient code outperforms efficient work done by people. In the grand scheme of things, as long as your code works, you are ahead of the game. Other than that, you might get some style points from other people if you do something a certain way.

If you are interested in learning more about the VBA language, I recommend VB and VBA in a Nutshell: The Language by Paul Lomax (O'Reilly). The book covers the VBA language very well and is very easy to read.

Get Integrating Excel and Access now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.