How to: Programmatically select worksheets
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.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.
If you want to select an existing worksheet in a VSTO 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 Worksheet host item directly.
Use 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
Use 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
- Work with worksheets
- How to: Programmatically print worksheets
- How to: Programmatically delete worksheets from workbooks
- How to: Programmatically hide worksheets
- How to: Programmatically protect worksheets
- Worksheet host item
- Global access to objects in Office projects
- Programmatic limitations of host items and host controls
- Optional parameters in Office solutions
- Host items and host controls overview