简体   繁体   English

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

[英]VBA fails when opening PowerPoint presentation on Windows 7

I wrote a VBA macro in Excel 2007 on Windows XP to copy data from an excel spreadsheet into a powerpoint presentation.我在 Windows XP 上的 Excel 2007 中编写了一个 VBA 宏,用于将数据从 excel 电子表格复制到 PowerPoint 演示文稿中。 When this macro enabled spreadsheet was run on a fresh install of Windows 7 it fails.当这个启用宏的电子表格在全新安装的 Windows 7 上运行时,它会失败。 So I pulled out the code that fails to pin point the problem and it seems to fail when trying to open an existing powerpoint file.因此,我提取了无法确定问题的代码,并且在尝试打开现有的 powerpoint 文件时似乎失败了。 I have tried running this code in both Office 2010 and Office 2007.我已尝试在 Office 2010 和 Office 2007 中运行此代码。

The code I am trying to use it (just the problem parts shown below)我正在尝试使用它的代码(只是下面显示的问题部分)

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

The macro fails on the Presentations.Open line above with the following error宏在上面的 Presentations.Open 行上失败,并出现以下错误

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

I have already enabled the PowerPoint 12.0 Object Library in the references settings in the VBEditor for the spreadsheet.我已经在电子表格的 VBEditor 的引用设置中启用了 PowerPoint 12.0 对象库。 All the other references match exactly with the file that runs without error on my Windows XP box.所有其他引用都与在我的 Windows XP 机器上运行且没有错误的文件完全匹配。

I have looked all over the web for an answer and cant find anything.我在网上到处寻找答案,但找不到任何东西。 I read something about Windows 7 and offline files, so tried turning that off but it didnt help.我阅读了一些有关 Windows 7 和脱机文件的信息,因此尝试将其关闭,但没有帮助。

I am logged in as an administrator user as well, and tried moving the pptx that I am opening to other directories as well with no success.我也以管理员用户身份登录,并尝试将我正在打开的 pptx 也移动到其他目录,但没有成功。

I am running the following version of Windows:我正在运行以下版本的 Windows:

Windows 7 Professional
Service Pack 1
64 Bit

Any help would be appreciated!任何帮助,将不胜感激!

Is PATH_TO_FILE a variable (or constant)?? PATH_TO_FILE 是变量(或常量)吗?

If so shouldn't it be如果是这样不应该

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

This does work in office 2016 on Win7 SP1 64bit OS这确实适用于 Win7 SP1 64 位操作系统上的 office 2016

Should be good for Office 2010.应该适用于 Office 2010。

Could be John's advise on the path to file, also.也可能是约翰对文件路径的建议。

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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM