[原创]vb 中调用powerpoint 对象错误1

本文介绍了一种在使用VBA代码自动打开PowerPoint文件时出现的"thepowerpointframewindowdoesnotexist"错误,并提供了解决方案。关键是确保在尝试打开演示文稿前至少显示一次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
 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.Net学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值