Udostępnij za pośrednictwem


How to: Change Excel Properties Using Visual Studio Project Automation

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

Microsoft Office version

  • Excel 2007

  • Excel 2003

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

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

Example

Sub ChangeProperties()
    ' Find the Visual Studio Tools for 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

Concepts

Visual Studio Tools for Office Project Extensibility Overview

Other Resources

Project Extensibility in Visual Studio Tools for Office