자동화를 사용하여 Visual Basic .NET 2002 또는 Visual Basic .NET 2003을 사용하여 PowerPoint 프레젠테이션을 만들고 표시하는 방법

요약

이 문서에서는 자동화를 사용하여 Microsoft Visual Basic .NET 2002 또는 Visual Basic .NET 2003을 사용하여 Microsoft PowerPoint 프레젠테이션을 만들고 표시하는 방법을 설명합니다.

추가 정보

Microsoft PowerPoint용 자동화 클라이언트 만들기

  1. Microsoft Visual Studio .NET 2002 또는 Visual Studio .NET 2003을 시작합니다. [파일] 메뉴에서 [새로 만들기]를 클릭한 다음 [프로젝트]를 클릭합니다. Visual Basic 프로젝트 형식에서 Windows 애플리케이션을 선택합니다. Form1은 기본적으로 만들어집니다.

  2. Microsoft PowerPoint 개체 라이브러리 및 Microsoft Graph 개체 라이브러리에 대한 참조를 추가합니다. 이렇게 하려면 다음과 같이 하십시오.

    1. 프로젝트 메뉴에서 참조 추가를 클릭합니다.
    2. COM 탭에서 Microsoft PowerPoint 개체 라이브러리를 찾은 다음 선택을 클릭합니다. 또한 Microsoft Graph 개체 라이브러리를 찾은 다음 선택을 클릭합니다.

    참고 Microsoft Office 2003 이상 버전의 Microsoft Office에는 PIA(기본 Interop 어셈블리)가 포함되어 있습니다. Microsoft Office XP에는 PIA가 포함되지 않지만 다운로드할 수 있습니다.

  3. [참조 추가] 대화 상자에서 [확인]을 클릭하여 선택 내용을 적용합니다.

  4. 보기 메뉴에서 도구 상자를 선택하여 도구 상자를 표시하고 Form1에 단추를 추가합니다.

  5. Button1을 두 번 클릭합니다. 양식의 코드 창이 나타납니다.

  6. 코드 창에서 다음 코드를 찾습니다.

        Private Sub Button1_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
    
    End Sub
    
    

    다음 코드로 바꿉 있습니다.

        Private Sub Button1_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
    
    Const sTemplate = _
               "C:\Program Files\Microsoft Office\Templates\Presentation Designs\Blends.pot"
            Const sPic = "C:\WINNT\Soap Bubbles.bmp"
    
    Dim oApp As PowerPoint.Application
            Dim oPres As PowerPoint.Presentation
            Dim oSlide As PowerPoint.Slide
            Dim bAssistantOn As Boolean
    
    'Start Powerpoint and make its window visible but minimized.
            oApp = New PowerPoint.Application()
            oApp.Visible = True
            oApp.WindowState = PowerPoint.PpWindowState.ppWindowMinimized
    
    'Create a new presentation based on the specified template.
            oPres = oApp.Presentations.Open(sTemplate, , , True)
    
    'Build Slide #1:
            'Add text to the slide, change the font and insert/position a 
            'picture on the first slide.
            oSlide = oPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
            With oSlide.Shapes.Item(1).TextFrame.TextRange
                .Text = "My Sample Presentation"
                .Font.Name = "Comic Sans MS"
                .Font.Size = 48
            End With
            oSlide.Shapes.AddPicture(sPic, False, True, 150, 150, 500, 350)
            oSlide = Nothing
    
    'Build Slide #2:
            'Add text to the slide title, format the text. Also add a chart to the
            'slide and change the chart type to a 3D pie chart.
            oSlide = oPres.Slides.Add(2, PowerPoint.PpSlideLayout.ppLayoutTitleOnly)
            With oSlide.Shapes.Item(1).TextFrame.TextRange
                .Text = "My Chart"
                .Font.Name = "Comic Sans MS"
                .Font.Size = 48
            End With
            Dim oChart As Graph.Chart
            oChart = oSlide.Shapes.AddOLEObject(150, 150, 480, 320, _
                        "MSGraph.Chart.8").OLEFormat.Object
            oChart.ChartType = Graph.XlChartType.xl3DPie
            oChart = Nothing
            oSlide = Nothing
    
    'Build Slide #3:
            'Add a text effect to the slide and apply shadows to the text effect.
            oSlide = oPres.Slides.Add(3, PowerPoint.PpSlideLayout.ppLayoutBlank)
            oSlide.FollowMasterBackground = False
            Dim oShape As PowerPoint.Shape
            oShape = oSlide.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffect27, _
                "The End", "Impact", 96, False, False, 230, 200)
            oShape.Shadow.ForeColor.SchemeColor = PowerPoint.PpColorSchemeIndex.ppForeground
            oShape.Shadow.Visible = True
            oShape.Shadow.OffsetX = 3
            oShape.Shadow.OffsetY = 3
            oShape = Nothing
            oSlide = Nothing
    
    'Modify the slide show transition settings for all 3 slides in
            'the presentation.
            Dim SlideIdx(3) As Integer
            SlideIdx(0) = 1
            SlideIdx(1) = 2
            SlideIdx(2) = 3
            With oPres.Slides.Range(SlideIdx).SlideShowTransition
                .AdvanceOnTime = True
                .AdvanceTime = 3
                .EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut
            End With
            Dim oSettings As PowerPoint.SlideShowSettings
            oSettings = oPres.SlideShowSettings
            oSettings.StartingSlide = 1
            oSettings.EndingSlide = 3
    
    'Prevent Office Assistant from displaying alert messages.
            bAssistantOn = oApp.Assistant.On
            oApp.Assistant.On = False
    
    'Run the slide show and wait for the slide show to end.
            oSettings.Run()
            Do While oApp.SlideShowWindows.Count >= 1
                System.Windows.Forms.Application.DoEvents()
            Loop
            oSettings = Nothing
    
    'Reenable Office Assisant, if it was on.
            If bAssistantOn Then
                oApp.Assistant.On = True
                oApp.Assistant.Visible = False
            End If
    
    'Close the presentation without saving changes and quit PowerPoint.
            oPres.Saved = True
            oPres.Close()
            oPres = Nothing
            oApp.Quit()
            oApp = Nothing
            GC.Collect()
        End Sub
    
    

    참고 이 코드에서 sTemplate 및 sPic 상수는 PowerPoint 템플릿 및 그림에 대한 전체 경로와 파일 이름을 각각 나타냅니다. 시스템에 설치된 템플릿 또는 그림을 사용하기 위해 필요에 따라 이러한 경로를 수정합니다.

  7. Form1.vb의 맨 위에 다음 코드를 추가합니다.

    Imports Office = Microsoft.Office.Core
    Imports Graph = Microsoft.Office.Interop.Graph
    Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
    
  8. F5 키를 눌러 프로그램을 빌드한 다음 실행합니다.

  9. 폼에서 Button1을 클릭하여 만든 다음 PowerPoint 프레젠테이션을 표시합니다.

참조

자세한 내용은 다음 MSDN(Microsoft Developer Network) 웹 사이트를 참조하세요. Microsoft Office System 2003 교육용 Visual Studio Tools