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:

  1. Open a new workbook in Microsoft Excel.

  2. On the Insert menu click Macro, and then click Module.

  3. 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.

REFERENCES

Microsoft Press: "Microsoft Excel for Visual Basic Reference," Second Edition, pages 701-702, 863-864.

For more information about Worksheets Object, click the Answer Wizard tab in Microsoft Excel 7.0 Help and type:

   What is a Worksheets Object?


Additional query words: 5.00 5.00a 5.00c 7.00
Keywords : kbprg PgmOthr kbhowto
Version : 5.00 5.00c 7.00 | 5.00 5.00a
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 13, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.