Export (0) Print
Expand All
Expand Minimize

How to: Activate Workbooks


Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The Activate method of the Workbooks collection activates a Microsoft Office Excel 2003 workbook and selects the first sheet in the workbook.

To activate a workbook

  • Use the Activate method of the Workbooks collection.


If you want to activate the workbook associated with the project, you can use the ThisWorkbook reference.

To activate the workbook associated with the project

  • Activate the workbook using ThisWorkbook.


You can index into the Workbooks collection using either integers (indicating the position within the collection) or workbook names. If you want to refer to a workbook by name, however, you must be careful how you refer to it: you must use the name you see in the title bar, which does not include the ".xls" extension until you save the file.

To reference individual workbooks

  • Use the position number or the name of the workbook.

    Excel.Workbook wb = this.Application.Workbooks[1];
    // Before Book1 is saved:
    wb = this.Application.Workbooks["Book1"];
    // After Book1 is saved:
    wb = this.Application.Workbooks["Book1.xls"];

See Also

Community Additions

© 2015 Microsoft