你目前正处于脱机状态,正在等待 Internet 重新连接

如何使用 Visual Basic 使 PowerPoint 在 Office 2003、Office XP Developer 和 Office 2000 Developer 中自动运行

针对 Office 2003 的支持已终止

Microsoft 已于 2014 年 4 月 8 日终止了针对 Office 2003 的支持。该更改已影响到您的软件更新和安全选项。 了解这一措施对于您的含义以及如何继续保持受保护状态。

概要
本文介绍如何使用 Microsoft Visual Basic 使 Microsoft PowerPoint 在 Microsoft Office 2003、Microsoft Office XP Developer 和 Microsoft Office 2000 Developer 中自动运行。
更多信息
通过使用 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 支持网站:
属性

文章 ID:222929 - 上次审阅时间:01/27/2006 09:26:00 - 修订版本: 5.1

  • Microsoft Office Standard Edition 2003
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition
  • Microsoft Visual Basic 5.0 专业版
  • Microsoft Visual Basic 6.0 专业版
  • Microsoft Visual Basic 5.0 企业版
  • Microsoft Visual Basic 6.0 企业版
  • Microsoft Office PowerPoint 2003
  • Microsoft PowerPoint 2002 标准版
  • Microsoft PowerPoint 2000 标准版
  • Microsoft PowerPoint 97 标准版
  • kbhowto kbautomation KB222929
反馈