Microsoft KB Archive/141291

= Microsoft Knowledge Base =

XL: A Description of the Sheets and Worksheets Objects
Last reviewed: June 13, 1997

Article ID: Q141291

The information in this article applies to:


 * Microsoft Excel for Windows 95, version 7.0
 * Microsoft Excel for Windows, versions 5.0, 5.0c
 * Microsoft Excel for the Macintosh, versions 5.0, 5.0a

SUMMARY
In Microsoft Excel, you can specify the difference in Sheets and Worksheets object collections when you write Visual Basic for Applications code.

MORE INFORMATION
The Sheets collection object is a collection of sheets in a workbook. The Sheets collection can contain Worksheet, Chart, Module, and DialogSheet objects. The Worksheets collection object is made up of worksheets in a workbook. A worksheet can be a Microsoft Excel 5.x or 4.x worksheet.

By referencing the Sheets object collection, you reference every sheet in the specified or active workbook by its assigned name or index number. In contrast, when you refer to the Worksheets object collection, you reference only worksheets and macro sheets.

To test the difference between the Sheets and Worksheets object collections, use the following steps:

 Open a new workbook in Microsoft Excel. On the Insert menu click Macro, and then click Module.  On the new module sheet, type the following code: Sub test MsgBox Sheets(1).Name & Chr(13) & Worksheets(1).Name End Sub 

When you run the macro, the name of the first sheet in the Sheets object collection index is displayed (in this case the name is "Module1"). The next line of the message box displays "Sheet1," which is the first worksheet in the Worksheets object collection.