Microsoft Office Tutorials and References
In Depth Information
Explore the Excel Object Model
Explore the Excel
To program Excel with VBA, you need to
understand the Excel object model.
In the programming lexicon, an object model is
a complete summary of the objects associated
with a particular program or feature, the
hierarchy used by those objects, and the
properties and methods supported by each
object. Here an object is a distinct, manipulable
item such as a worksheet or range; a property is
a programmable characteristic of an object
such as a worksheet’s name or whether a range
is formatted with bold text; and a method is an
action you can perform on an object, such as
creating a new worksheet or clearing the
formatting from a range.
This section shows you a few properties and
methods for the three main objects in the
Excel model: the workbook, the worksheet,
and the range.
You can use VBA to create new workbooks, open, save, and close workbooks, and more. You can
reference a specific workbook either by using the ActiveWorkbook object, which represents the
workbook that currently has the focus, or by using the Workbooks collection, which represents all
the workbooks currently open in Excel. Here are some examples:
Returns the filename of the workbook.
Returns the location of the workbook.
Returns the location and filename of the workbook.
Returns False if the workbook has unsaved changes.
Creates a new workbook.
Opens an existing workbook.
Saves a workbook.
Closes a workbook.