VB播放PPT
我复制MSDN上的代码已经调试成功。但发现在PPT播放完成最后显示POWERPOINT系统信息“播放结束,按任意键退出”。请问有没有办法把这个跳过去? --------------------编程问答-------------------- 自己顶起~ --------------------编程问答-------------------- 模拟发送一个回车键试试 --------------------编程问答-------------------- 咋写模拟?麻烦楼上的给个代码。。本人太业余。谢谢 --------------------编程问答-------------------- o --------------------编程问答-------------------- 刚试过用SENDKEYS没有任何效果。必须要鼠标点一下。 --------------------编程问答-------------------- 先激活PPT让程序获得焦点记得是activeapp这个函数,然后再用SENDKEYS发送回车键 --------------------编程问答-------------------- 找不到啊。。麻烦给个详细方法 --------------------编程问答-------------------- 最好贴上代码,不然大家不好帮你解决…… --------------------编程问答-------------------- 文章ID: 303717最近更新: 2007-1-17
--------------------------------------------------------------------------------
这篇文章中的信息适用于:
Microsoft Visual Basic .NET 2003 标准版
Microsoft Visual .NET 2002 标准版
Microsoft Office PowerPoint 2003
Microsoft PowerPoint 2002 标准版
--------------------------------------------------------------------------------
有关本文的 Microsoft Visual C# .NET 版本,请参阅 303718。
有关本文的 Microsoft Visual C++ .NET 版本,请参阅 308336。
概要
本文逐步介绍了如何在 Visual Basic .NET 中使 PowerPoint 自动运行以创建并显示 PowerPoint 演示文稿。
更多信息
为 Microsoft PowerPoint 创建自动化客户端
启动 Microsoft Visual Studio .NET。在文件菜单上,单击新建,然后单击项目。从 Visual Basic 项目类型中选择 Windows 应用程序。默认情况下会创建 Form1。
添加对 Microsoft PowerPoint 对象库和 Microsoft Graph 对象库的引用。为此,请按照下列步骤操作:
在项目菜单上,单击添加引用。
在 COM 选项卡上,找到 Microsoft PowerPoint 对象库,然后单击选择。还应找到 Microsoft Graph 对象库,然后单击选择。
注意:Microsoft Office 2003 包含主 Interop 程序集 (PIA)。Microsoft Office XP 不包含 PIA,但您可以下载 PIA。 有关 Office XP PIA 的其他信息,请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章:
328912 INFO:Microsoft Office XP PIA 可供下载
在添加引用对话框中单击确定以接受您的选择。
在视图菜单上,选择工具箱以显示工具箱,然后向 Form1 添加一个按钮。
双击 Button1。出现该窗体的代码窗口。
在代码窗口中,将以下代码
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 模板和图片的完整路径及文件名。按照需要修改这些路径以使用安装在您系统中的模板或图片。
将以下代码添加到 Form1.vb 的顶部:
Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
Imports Office = Microsoft.Office.Core
Imports Graph = Microsoft.Office.Interop.Graph
按 F5 键生成并运行该程序。
在窗体上单击 Button1 创建并显示 PowerPoint 演示文稿。
参考
有关更多信息,请访问下面的 Microsoft Web 站点:
Microsoft Office Development with Visual Studio(使用 Visual Studio 进行 Microsoft Office 开发)
http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx
有关 PowerPoint 自动化的其他信息,请单击下面的文章编号,以查看 Microsoft 知识库中的文章:
180616 HOWTO:Use MFC to Create and Show a PowerPoint Presentation
222929 HOWTO:Automate PowerPoint Using Visual Basic
Keywords: kbautomation kbhowto KB303717
--------------------编程问答-------------------- 试了下,模拟鼠标操作似乎没有用……帮顶! --------------------编程问答-------------------- 顶起来,求高手解答 --------------------编程问答-------------------- 麻烦高人解下此贴。 --------------------编程问答--------------------
补充:.NET技术 , VB.NET