How to: Programmatically Create New Workbooks


When you create a workbook programmatically, it is a native Microsoft.Office.Interop.Excel.Workbook object, not a Microsoft.Office.Tools.Excel.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 Microsoft.Office.Tools.Excel.Workbook host item for a Microsoft.Office.Interop.Excel.Workbook object in VSTO Add-in project. For more information, see Extending 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();

    System_CAPS_ICON_note.jpg 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.

Extending Word Documents and Excel Workbooks in VSTO Add-ins at Run Time
Adding Controls to Office Documents at Run Time
Working with Workbooks
How to: Programmatically Open Workbooks
How to: Programmatically Save Workbooks
How to: Programmatically Close Workbooks
Programmatic Limitations of Host Items and Host Controls
Optional Parameters in Office Solutions
Host Items and Host Controls Overview