在Windows 7上打开PowerPoint演示文稿时VBA失败 [英] VBA fails when opening PowerPoint presentation on Windows 7

查看:237
本文介绍了在Windows 7上打开PowerPoint演示文稿时VBA失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows XP上的Excel 2007中编写了VBA宏,用于将数据从excel电子表格复制到PowerPoint演示文稿中. 在全新安装的Windows 7上运行启用了宏的电子表格时,该电子表格将失败. 因此,我拔出了无法查明问题的代码,并且在尝试打开现有的powerpoint文件时似乎失败了.我已经尝试在Office 2010和Office 2007中都运行此代码.

I wrote a VBA macro in Excel 2007 on Windows XP to copy data from an excel spreadsheet into a powerpoint presentation. When this macro enabled spreadsheet was run on a fresh install of Windows 7 it fails. 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. I have tried running this code in both Office 2010 and 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

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

The macro fails on the Presentations.Open line above with the following error

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

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

I have already enabled the PowerPoint 12.0 Object Library in the references settings in the VBEditor for the spreadsheet. All the other references match exactly with the file that runs without error on my Windows XP box.

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

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.

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

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.

我正在运行以下版本的Windows:

I am running the following version of Windows:

Windows 7 Professional
Service Pack 1
64 Bit

任何帮助将不胜感激!

推荐答案

这在Win7 SP1 64位操作系统上的Office 2016中确实有效

This does work in office 2016 on Win7 SP1 64bit OS

应该对Office 2010有益.

Should be good for Office 2010.

也可能是John关于文件路径的建议.

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 

这篇关于在Windows 7上打开PowerPoint演示文稿时VBA失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆