在 Windows 7 上打开 PowerPoint 演示文稿时 VBA 失败

问题描述 投票:0回答:2

我在 Windows XP 上的 Excel 2007 中编写了一个 VBA 宏,用于将 Excel 电子表格中的数据复制到 Powerpoint 演示文稿中。 当此启用宏的电子表格在全新安装的 Windows 7 上运行时,它会失败。 因此,我提取了未能查明问题的代码,并且在尝试打开现有的 powerpoint 文件时似乎失败了。我尝试在 Office 2010 和 Office 2007 中运行此代码。

我尝试使用它的代码(只是下面显示的问题部分)

Sub test()
   Dim PowerPointApplication As PowerPoint.Application
   Dim PowerPointFile As PowerPoint.Presentation

   Set PowerPointApplication = CreateObject("PowerPoint.Application")
   Set PowerPointFile = PowerPointApplication.Presentations.Open("PATH_TO_FILE\test.pptx")
End Sub

宏在上面的Presentations.Open行上失败,并出现以下错误

Run-time error '-2147467259 (80004005)':
Method 'Open' of object 'Presentations' failed

我已经在电子表格的 VBEditor 的引用设置中启用了 PowerPoint 12.0 对象库。所有其他引用与在我的 Windows XP 机器上运行且没有错误的文件完全匹配。

我在网上寻找答案,但找不到任何东西。我读到了一些有关 Windows 7 和脱机文件的内容,因此尝试将其关闭,但没有帮助。

我也以管理员用户身份登录,并尝试将我打开的 pptx 移动到其他目录,但没有成功。

我运行的是以下版本的 Windows:

Windows 7 Professional
Service Pack 1
64 Bit

如有任何帮助,我们将不胜感激!

excel vba windows-7 powerpoint
2个回答
0
投票

PATH_TO_FILE 是变量(或常量)吗??

如果是的话,那不应该是这样吗

PowerPointFile = PowerPointApplication.Presentations.Open(PATH_TO_FILE & "\test.pptx")


0
投票

这适用于 Win7 SP1 64 位操作系统的 Office 2016

应该适用于 Office 2010。

也可能是约翰对文件路径的建议。

Sub test()
Dim PowerPointFile As PowerPoint.Presentation
Dim PPTObj As Object
Set PPTObj = CreateObject("PowerPoint.application")

Set PowerPointFile = PPTObj.Presentations.Open("C:\test.pptx")

End Sub 
© www.soinside.com 2019 - 2024. All rights reserved.