Megosztás a következőn keresztül:


How to: Create New Workbooks

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

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

Starting in Visual Studio 2008 Service Pack 1 (SP1), you can generate a Microsoft.Office.Tools.Excel.Workbook host item for a Workbook object in an application-level project. For more information, see Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time.

To create a new workbook

  • Use the Add(Object) method of the Workbooks collection.

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

    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(Object) method.

See Also

Tasks

How to: Open Workbooks

How to: Save Workbooks

How to: Close Workbooks

Concepts

Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time

Adding Controls to Office Documents at Run Time

Working with Workbooks

Programmatic Limitations of Host Items and Host Controls

The Variable missing and Optional Parameters in Office Solutions

Host Items and Host Controls Overview