如何使用 Office 2003、Office XP Developer 和 Office 2000 Developer 中的 Visual Basic 來自動化 PowerPoint

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

本文已封存。本文係以「現狀」提供且不會再更新。
結論
本文將告訴您,如何使用 Microsoft Office 2003、Microsoft Office XP Developer 和 Microsoft Office 2000 Developer 中的 Microsoft Visual Basic 來自動化 Microsoft PowerPoint。
其他相關資訊
您可以使用 PowerPoint 中的自動化,以程式設計方式列印、顯示投影片,並且執行大多數能夠以互動方式進行的操作。請依照下列步驟建置並執行 Visual Basic 自動化範例:
  1. 建立新的標準 EXE 專案。根據預設會建立 Form1。
  2. 將 CommandButton 加入預設表單。
  3. 按一下 [專案] 功能表中的 [參考],並加入 [Microsoft PowerPoint 8.0 物件程式庫][Microsoft Office 8.0 物件程式庫]。如果是 Office 2000,則為 9.0 版的型別程式庫。如果是 Office 2002,則為 10.0 版。如果是 Microsoft Office 2003,則為 11.0 版。
  4. 將下列程式碼加入您的表單程式碼視窗:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()    ' Start PowerPoint.    Dim ppApp As PowerPoint.Application    Set ppApp = CreateObject("Powerpoint.Application")     ' Make it visible.    ppApp.Visible = True     ' Add a new presentation.    Dim ppPres As PowerPoint.Presentation    Set ppPres = ppApp.Presentations.Add(msoTrue)     ' Add a new slide.    Dim ppSlide1 As PowerPoint.Slide    Set ppSlide1 = ppPres.Slides.Add(1, ppLayoutText)     ' Add some text.    ppSlide1.Shapes(1).TextFrame.TextRange.Text = "My first slide"    ppSlide1.Shapes(2).TextFrame.TextRange.Text = "Automating Powerpoint is easy" & vbCr & "Using Visual Basic is fun!"     ' Add another slide, with a chart.    Dim ppSlide2 As PowerPoint.Slide    Set ppSlide2 = ppPres.Slides.Add(2, ppLayoutTextAndChart)        ' Add some text.    ppSlide2.Shapes(1).TextFrame.TextRange.Text = "Slide 2's topic"    ppSlide2.Shapes(2).TextFrame.TextRange.Text = "You can create and use charts in your Powerpoint slides!"     ' Add a chart in the same location as the old one.    Dim cTop As Double    Dim cWidth As Double    Dim cHeight As Double    Dim cLeft As Double    With ppSlide2.Shapes(3)        cTop = .Top        cWidth = .Width        cHeight = .Height        cLeft = .Left        .Delete    End With    ppSlide2.Shapes.AddOLEObject cLeft, cTop, cWidth, cHeight, "MSGraph.Chart"     ' Add another slide, with an organization chart.    Dim ppSlide3 As PowerPoint.Slide    Set ppSlide3 = ppPres.Slides.Add(3, ppLayoutOrgchart)     ' Add some text.    ppSlide3.Shapes(1).TextFrame.TextRange.Text = "The rest is only limited by your Imagination"     ' Add an Org Chart in the same location as the old one.    With ppSlide3.Shapes(2)        cTop = .Top        cWidth = .Width        cHeight = .Height        cLeft = .Left        .Delete    End With    ppSlide3.Shapes.AddOLEObject cLeft, cTop, cWidth, cHeight, "OrgPlusWOPX.4" 'OrgPlusWOPX.4     ' is an object of the application Microsoft Organization Chart     ' Setup slide show properties.    With ppPres.Slides.Range.SlideShowTransition        .EntryEffect = ppEffectRandom        .AdvanceOnTime = msoTrue        .AdvanceTime = 5 ' 5 seconds per slide    End With     ' Prepare and run the slide show.    With ppPres.SlideShowSettings        .ShowType = ppShowTypeKiosk        .LoopUntilStopped = msoTrue        .RangeType = ppShowAll        .AdvanceMode = ppSlideShowUseSlideTimings        .Run    End With     ' Sleep so user can watch the show.    Sleep (15000)     ' Clean up.    ppApp.QuitEnd Sub					
  5. 執行專案。
参考
如需有關 Office 自動化的詳細資訊,請造訪 Microsoft Office Development 支援網站:
內容

文章識別碼:222929 - 最後檢閱時間:12/05/2015 13:28:26 - 修訂: 5.1

Microsoft Office Standard Edition 2003, Microsoft Office XP Developer Edition, Microsoft Office 2000 Developer Edition, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic 6.0 Enterprise Edition, Microsoft Office PowerPoint 2003, Microsoft PowerPoint 2002 Standard Edition, Microsoft PowerPoint 2000 Standard Edition, Microsoft PowerPoint 97 Standard Edition

  • kbnosurvey kbarchive kbhowto kbautomation KB222929
意見反應