How to: Add New Worksheets to 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
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
You can programmatically add a new worksheet to the collection of worksheets in the workbook.
To add a new worksheet to a workbook in a document-level customization
Use the Add(Object, Object, Object, Object) method of the Sheets collection.
Dim newWorksheet As Excel.Worksheet newWorksheet = CType(Globals.ThisWorkbook.Worksheets.Add(), Excel.Worksheet)
Excel.Worksheet newWorksheet; newWorksheet = (Excel.Worksheet)Globals.ThisWorkbook.Worksheets.Add( missing, missing, missing, missing);
The new worksheet is a native Worksheet object and not a host item. If you want to add a Microsoft.Office.Tools.Excel.Worksheet host item, you should add the worksheet at design time.
To add a new worksheet to a workbook in an application-level add-in
Use the Add(Object, Object, Object, Object) method of the Sheets collection.
Dim newWorksheet As Excel.Worksheet newWorksheet = CType(Me.Application.Worksheets.Add(), Excel.Worksheet)
Excel.Worksheet newWorksheet; newWorksheet = (Excel.Worksheet)this.Application.Worksheets.Add( missing, missing, missing, missing);
The new worksheet is a native Worksheet object and not a host item. Starting in Visual Studio 2008 Service Pack 1 (SP1), you can generate a Microsoft.Office.Tools.Excel.Worksheet host item from the native Worksheet object. For more information, see Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time.
See Also
Tasks
How to: Delete Worksheets from Workbooks
Concepts
Host Items and Host Controls Overview
Global Access to Objects in Visual Studio Tools for Office Projects
The Variable missing and Optional Parameters in Office Solutions
Other Resources
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a code example that can be used in an application-level add-in. |
Customer feedback. |