Excel Workbooks

by Linda Quinn

Close Window


An Excel Workbook is a file with the extension .xls .

The basic building block of Excel starts with the workbook.

    [See the Excel object model]




Declare a variable for an Excel workbook.


SET the workbook variable to an Existing workbook.
The SET statement is used to assign a variable to an object.
In this example, the SET statement also OPENS the workbook.

Notice that the SET statement Opens a workbook from the workbooks collection.
All workbook objects are part of the workbook collection of all Excel workbooks.
Creating or opening a specific workbook must reference the workbooks collection.


Set the workbook variable to a New workbook.
This example uses the SET statement to create a NEW workbook
and then save it with its new name:

Notice that the new workbook is added to the workbooks collection.


In both of these example, the workbook will be refered to in the VBA code as wkb.

This will be used to reference objects within the workbook.

For Example:
    wkb.Worksheets(1)
OR
    wkb.worksheets("Sheet1")


Closing a workbook
To close a workbook, we use the Close method with our workbook name.


Saving and Closing a workbook
Either of these samples will save the workbook before closing it.








=================================================================
This content was created by Linda Quinn of LQNet.

See http://www.lqnet.com for a great collection of articles on this and other topics.

=================================================================
Copyright © 2006-2009, LQ Systems,Inc. All rights reserved.


====================================================================
Want an expert to help with your project?    LQ Systems, Inc.   Business Solutions
====================================================================