Export (0) Print
Expand All

How to: Change Excel Properties Using Visual Studio Project Automation

Note Required applications

The features in this topic are available only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

  • Microsoft Office 2003

This example changes a Microsoft Office Excel 2003 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 requires:

  • An Excel Workbook project in Visual Basic named ChangeProperties. The project must be the first project in the solution.

  • 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

Community Additions

ADD
Show:
© 2014 Microsoft