How to: Change Excel Properties Using Visual Studio Project Automation

This example changes a Microsoft Office Excel worksheet property to rename the worksheet.

Applies to: The information in this topic applies to document-level projects for Excel 2007 and Excel 2010. For more information, see Features Available by Office Application and Project Type.

Example

Sub ChangeProperties()
    ' Find the Office project.
    Dim vstProject As Project = DTE.Solution.Item(1)

    ' Find the Excel workbook.
    Dim docItem As ProjectItem = _
        vstProject.ProjectItems.Item("ChangeProperties.xls")

    ' Find and rename the worksheet.
    Dim sheetItem As ProjectItem = _
        docItem.ProjectItems.Item("Sheet1.vb")
    Dim sheetProperties As Properties = sheetItem.Properties
    sheetProperties.Item("VST.FileName").Value = "RenamedSheet.vb"
End Sub

Compiling the Code

This example has the following requirements:

  • An Excel workbook document-level project in Visual Basic named ChangeProperties. The project must be the first project in the solution.

  • The format of the workbook in the project must be Excel 97-2003 workbook (.xls).

  • A worksheet named Sheet1.vb in the workbook.

Robust Programming

Add the code to a module in the Visual Studio Macros integrated development environment (IDE).

See Also

Tasks

Walkthrough: Creating a New Office Project Using Visual Studio Project Automation

How to: Add Worksheets to Workbooks Using Visual Studio Project Automation

Other Resources

Extensibility in Office Projects

Extensibility in Office Projects