Appendix B. VBA Basics

This appendix provides a short tutorial on some basic VBA programming structures. Clearly, this isn't designed to teach you everything, and you should be familiar with basic programming concepts, such as variables and objects, but it should give you some information to help you get through the tasks in this book.

Dim and Set Statements

The Dim statement is used to declare a variable and assign it to a particular type. If the variable is an object, use the Set statement to assign an object to the variable. If the variable is not an object, use the variable, an equal sign, and the value. The following code example shows how to declare a variable called xlapp and set it to a new Excel application:

Dim xlapp as Excel.Application
Set xlapp = New Excel.Application

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.