How to: Programmatically create new 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

When you create a workbook programmatically, it is a native Workbook object, not a Workbook host item.

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.

You can generate a Workbook host item for a Workbook object in VSTO Add-in project. For more information, see Extend Word documents and Excel workbooks in VSTO Add-ins at run time.

To create a new workbook

  1. Use the Add method of the Workbooks collection.

    Excel.Workbook newWorkbook = this.Application.Workbooks.Add();
    
    Dim newWorkbook As Excel.Workbook = Me.Application.Workbooks.Add()
    

    Note

    You can create a workbook based on a template other than the default template: pass the template you want to use as a parameter to the Add method.

See also