방법: Visual Studio 프로젝트 자동화를 사용하여 통합 문서에 워크시트 추가

업데이트: 2007년 11월

적용 대상

이 항목의 정보는 지정된 Visual Studio Tools for Office 프로젝트 및 Microsoft Office 버전에만 적용됩니다.

프로젝트 형식

  • 문서 수준 프로젝트

Microsoft Office 버전

  • Excel 2007

  • Excel 2003

자세한 내용은 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

이 예제에서는 Visual Studio 디자이너에 열려 있는 기존의 Microsoft Office Excel 통합 문서에 새 워크시트를 추가합니다.

예제

Sub AddWorksheet()
    ' 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("ExcelWorkbook1.xls")

    ' Activate the Solution Explorer window.
    Dim solExpl As Window = _
        DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer)
    solExpl.Activate()

    ' Find and select the Excel workbook.
    Dim uiHier As UIHierarchy = solExpl.Object

    ' The path follows the pattern
    ' SolutionName\ProjectName\WorkbookName.
    Dim item As UIHierarchyItem = _
        uiHier.GetItem("ExcelWorkbook1\ExcelWorkbook1.xls")
    item.Select(vsUISelectionType.vsUISelectionTypeSelect)

    ' Execute the shortcut menu command to add a new worksheet.
    Dim commandGuid As String = _
        "{AE97F291-448D-4F9F-93A8-B0D2B78475A4}"

    ' Set commandID to 1 to add a new worksheet, 2 to add a new chart.
    Dim commandID As Integer = 1 
    Dim customIn As Object
    Dim customOut As Object
    DTE.Commands.Raise(commandGuid, commandID, customIn, customOut)
End Sub

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

  • Visual Studio 디자이너에 열려 있는 ExcelWorkbook1이라는 프로젝트에 ExcelWorkbook1이라는 Excel 통합 문서가 있어야 합니다. 솔루션에 다른 프로젝트는 없어야 합니다.

  • 프로젝트에 있는 통합 문서가 Excel 97-2003 통합 문서(.xls) 형식이어야 합니다.

  • ExcelWorkbook1 프로젝트를 만들 때 새 프로젝트 대화 상자에서 솔루션용 디렉터리 만들기를 선택하지 말아야 합니다.

강력한 프로그래밍

Visual Studio Macros IDE(통합 개발 환경)의 모듈에 코드를 추가합니다.

옵션 대화 상자에서 솔루션 항상 표시 옵션의 선택을 취소합니다. 이 대화 상자에 액세스하려면 도구 메뉴에서 옵션을 클릭한 다음 프로젝트 및 솔루션 폴더를 선택하고 일반을 클릭합니다.

참고 항목

작업

연습: Visual Studio 프로젝트 자동화를 사용하여 새 Office 프로젝트 만들기

방법: Visual Studio 프로젝트 자동화를 사용하여 Excel 속성 변경

개념

Visual Studio Tools for Office 프로젝트 확장성 개요

기타 리소스

Visual Studio Tools for Office의 프로젝트 확장성