Visual Basic .NET 2002 veya Visual Basic .NET 2003 kullanarak PowerPoint sunusu oluşturmak ve göstermek için otomasyon kullanma

Özet

Bu makalede, Microsoft Visual Basic .NET 2002 veya Visual Basic .NET 2003 kullanarak bir Microsoft PowerPoint sunusu oluşturmak ve göstermek için otomasyonun nasıl kullanılacağı açıklanmaktadır.

Daha Fazla Bilgi

Microsoft PowerPoint için otomasyon istemcisi oluşturma

  1. Microsoft Visual Studio .NET 2002 veya Visual Studio .NET 2003'i başlatın. Dosya menüsünde Yeni'ye ve ardından Proje'ye tıklayın. Visual Basic Projeleri türlerinden Windows Uygulaması'nı seçin. Form1 varsayılan olarak oluşturulur.

  2. Microsoft PowerPoint Nesne Kitaplığı'na ve Microsoft Graph Nesne Kitaplığı'na başvuru ekleyin. Bunu yapmak için şu adımları uygulayın:

    1. Proje menüsünde Başvuru Ekle'ye tıklayın.
    2. COM sekmesinde Microsoft PowerPoint Nesne Kitaplığı'nı bulun ve Seç'e tıklayın. Ayrıca Microsoft Graph Nesne Kitaplığı'nı bulun ve Seç'e tıklayın.

    Not Microsoft Office 2003 ve sonraki Microsoft Office sürümlerinde Birincil Birlikte Çalışma Derlemeleri (PIA) bulunur. Microsoft Office XP PIA içermez, ancak indirilebilir.

  3. Seçimlerinizi kabul etmek için Başvuru Ekle iletişim kutusunda Tamam'a tıklayın.

  4. Görünüm menüsünde Araç Kutusu'nu seçerek Araç Kutusu'nu görüntüleyin ve Form1'e bir düğme ekleyin.

  5. Düğme1'e çift tıklayın. Formun kod penceresi görüntülenir.

  6. Kod penceresinde aşağıdaki kodu bulun

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

    değerini aşağıdaki kodla değiştirin:

        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
    
    

    Not Bu kodda, sTemplate ve sPic sabitleri sırasıyla bir PowerPoint şablonunun tam yolunu ve dosya adını ve bir resmi temsil eder. Sisteminizde yüklü bir şablon veya resim kullanmak için bu yolları gerektiği gibi değiştirin.

  7. Aşağıdaki kodu Form1.vb dosyasının en üstüne ekleyin:

    Imports Office = Microsoft.Office.Core
    Imports Graph = Microsoft.Office.Interop.Graph
    Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
    
  8. Programı derlemek ve çalıştırmak için F5 tuşuna basın.

  9. Formda Button1'e tıklayarak bir PowerPoint sunusu oluşturun ve gösterin.

Başvurular

Daha fazla bilgi için aşağıdaki Microsoft Developer Network (MSDN) Web sitesine bakın: Microsoft Office System 2003 Eğitimi için Visual Studio Araçları