VBA fails when opening PowerPoint presentation on Windows 7

你。 提交于 2019-12-12 11:21:56

问题


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

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

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. All the other references match exactly with the file that runs without error on my Windows XP box.

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.

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.

I am running the following version of Windows:

Windows 7 Professional
Service Pack 1
64 Bit

Any help would be appreciated!


回答1:


Is PATH_TO_FILE a variable (or constant)??

If so shouldn't it be

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




回答2:


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

Should be good for 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 


来源:https://stackoverflow.com/questions/20282386/vba-fails-when-opening-powerpoint-presentation-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!