Share via


How to: Select Worksheets

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

The Select method selects the specified object, which moves the user's selection to the new object. Use the Activate method if you want to bring focus to the object without changing the user's selection.

If you want to select an existing worksheet in an application-level add-in or if the worksheet was created at run time in a document-level customization, you must access it by using the Excel Sheets collection of the Excel workbook; otherwise, you can access the Microsoft.Office.Tools.Excel.Worksheet host item directly.

Using the Worksheet Host Item

In a document-level customization, add the following code to Sheet1.vb or Sheet1.cs.

To select the first worksheet in a workbook using a host item

  • Call the Select method of Sheet1.

    Globals.Sheet1.Select()
    
    Globals.Sheet1.Select(missing);
    

Using the Sheets Collection of the Excel Workbook

Access the worksheet by using the Excel Sheets collection.

To select the first worksheet in a workbook using the Sheets collection of the Excel workbook

  • Call the Select(Object) method of the Sheets collection to select the first worksheet of the active workbook.

    CType(Me.Application.ActiveWorkbook.Sheets(1), Excel.Worksheet).Select()
    
    ((Excel.Worksheet)this.Application.ActiveWorkbook.Sheets[1]).Select(missing);
    

See Also

Tasks

How to: Activate Workbooks

How to: Print Worksheets

How to: Delete Worksheets from Workbooks

How to: Hide Worksheets

How to: Protect Worksheets

Concepts

Working with Worksheets

Worksheet Host Item

Global Access to Objects in Visual Studio Tools for Office Projects

Programmatic Limitations of Host Items and Host Controls

The Variable missing and Optional Parameters in Office Solutions

Host Items and Host Controls Overview