Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Excel Solutions
 How to: Add New Worksheets to Workb...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0)
How to: Add New Worksheets to Workbooks

Updated: July 2008

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.

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 method of the Sheets collection.

    Visual Basic
    Dim newWorksheet As Excel.Worksheet
    newWorksheet = CType(Globals.ThisWorkbook.Worksheets.Add(), Excel.Worksheet)
    
    
    C#
    Excel.Worksheet newWorksheet;
    newWorksheet = (Excel.Worksheet)Globals.ThisWorkbook.Worksheets.Add(
        missing, missing, missing, missing);
    
    

    The new worksheet is a native Microsoft.Office.Interop.Excel..::.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

Date

History

Reason

July 2008

Added a code example that can be used in an application-level add-in.

Customer feedback.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker