45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:如何在vb中调用powerpoint对象错误?

如何在vb中调用powerpoint对象错误?

2016-08-29 03:19:09 来源:www.45fan.com 【

如何在vb中调用powerpoint对象错误?

[个人原创,如转载请说明出处]

错误:"the powerpoint frame window does not exist"

Private myp As PowerPoint.Application
Private Sub Command1_Click()
Dim mypp As PowerPoint.Presentation
Set myp = New PowerPoint.Application

Dim pptname As String
pptname = App.Path & "/test.ppt"

Set mypp = myp.Presentations.Open(pptname) -->错误发生位置

在microsoft support 中是这么说的:

This error will occur if you use the Application.Presentations.Open method before showing the PowerPoint application window at least once.
Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

If you want PowerPoint to be essentially invisible, you can use the following command to minimizePowerPoint's application window before opening the presentation file:

ppt.AppWindow.Windowstate = ppWindowMinimized

This line must come after the "ppt.AppWindow.Visible" command, otherwise the window will not be minimized. The code might look something like the following:

  Private Sub Form_Load()
   Dim ppt As Object
   Dim pres As Object
   Set ppt = CreateObject("PowerPoint.application.7")
   ppt.AppWindow.Visible = True
   ppt.AppWindow.Windowstate = ppWindowMinimized
   Set pres = ppt.presentations.open("c:/windows/desktop/test.ppt")
  End Sub
也就是说,必须在使用presentations.open之前最少应显示1次application。
powerpoint2003下与上述代码略有不同(在错误发生位置之前加入):
myp.Visible = msoTrue
myp.WindowState = ppWindowMinimized

 

本文地址:http://www.45fan.com/a/question/69046.html
Tags: 原创 PowerPoint 错误
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部