VB控制PPT有两种方式:

1.利用WebBrowser控件打开PPT(这种方式可以不装OFFICE)

首先勾选部件,如图:

然后敲入如下代码:

Public pptApp As Variant

Private Sub Form_Load()

WebBrowser1.Navigate (App.Path + “/t.ppt”)

Set pptApp = WebBrowser1.Document
End Sub

跳到指定页码:pptApp.SlideShowWindow.View.GotoSlide (页码)

跳到下一页:pptApp.SlideShowWindow.View.Next

跳到上一页:pptApp.SlideShowWindow.View.Last

2.引用powerpoint “Microsoft Powerpoint 11.0 Object Library”(这种方式必须装Office)

示例代码如下

Dim op As PowerPoint.Presentation

Dim moPptApp As PowerPoint.Application

Dim moPptPresentation As Object

Dim mnPptAppWidth As Single           ‘

Dim mnPptAppheight As Single          ‘

Set moPptApp = CreateObject(“PowerPoint.Application”)

Set moPptPresentation = moPptApp.Presentations.Open(App.Path & “\test.ppt”, , , False)  ‘打开应用程序目录下的test.ppt文件

With moPptPresentation.SlideShowSettings

.Run.Width = mnPptAppWidth    ‘设置宽度

.Run.Height = mnPptAppheight   ‘设置高度

.Run.Presentation.DisplayComments = False

.Run.Presentation.Saved = True

‘.Run

End With

mopptapp.quit  ‘退出。