Jaa


How to: Programmatically open workbooks

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

The Workbooks collection in Microsoft Office Excel makes it possible to work with all open workbooks and to open workbooks.

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.

To open an existing workbook

  1. Use the Open method of the Workbooks collection, passing in the path to the workbook.

    this.Application.Workbooks.Open(@"C:\Test\YourWorkbook.xlsx");
    
    Me.Application.Workbooks.Open("C:\Test\YourWorkbook.xlsx")
    

Compile the code

This code example requires the following:

  • A workbook named YourWorkbook.xls must exist in a directory named Test on drive C.

See also