So, several years ago I created an Excel VBA macro to open a series of PowerPoint files, grab some values to add to the Excel file and close the PPs. Worked great and saved tons of time. Come to use it again and it is crashing. It is clearly the opening and closing part that is the issue (stripped down code is below). The PP files are on the large side (>4mb) and take some time to open. What happens is the cycle is going along fine when after two or three PP files, VBA throws an exception and PP is left open with the failed file listed in the recovery window. The number of files it can get through is semi-random 2 to 3.
Exact error message:
Two things that might be the issue:
The version of PP that the slide files are 97-2003 while my PP version is now 2013 (though I probably originally was using Office 2010 when I wrote the macro). It is certainly the case that the OS is different (Win10 currently, probably Win7 or Win8 when I first wrote the code).
Possibly the speed of opening and closing the files is causing confusion given their size and time it takes to open them. Why this would become a problem now, I don't know. Nor do I know how I can assure that only one file is open at a time.
Any suggestions would be greatly appreciated. I can still save time by doing files 2-3 at a time but I'd like to understand what is going on and would really prefer just to be able to run the full set all at once. This situation will keep coming up in the future.
A user on another board suggested a DoEvents after the opening of the PP file but it has not changed the behavior.
Exact error message:
Run-time error '-2147417851 (80010105)':
Automation error
The server threw an exception.
Two things that might be the issue:
The version of PP that the slide files are 97-2003 while my PP version is now 2013 (though I probably originally was using Office 2010 when I wrote the macro). It is certainly the case that the OS is different (Win10 currently, probably Win7 or Win8 when I first wrote the code).
Possibly the speed of opening and closing the files is causing confusion given their size and time it takes to open them. Why this would become a problem now, I don't know. Nor do I know how I can assure that only one file is open at a time.
Any suggestions would be greatly appreciated. I can still save time by doing files 2-3 at a time but I'd like to understand what is going on and would really prefer just to be able to run the full set all at once. This situation will keep coming up in the future.
A user on another board suggested a DoEvents after the opening of the PP file but it has not changed the behavior.
Code:
Sub TestOpen()
Dim currPres As String
Dim currdir As String
Dim ppt As Object
Set ppt = CreateObject("PowerPoint.Application")
currdir = "C:\Users\Rich\Desktop\Test"
currPres = Dir(currdir & "\*.ppt")
Do Until currPres = ""
ppt.Presentations.Open currdir & "" & currPres, WithWindow:=msoFalse
MsgBox currPres
ppt.Presentations.Item(1).Close
currPres = Dir
Loop
ppt.Quit
End Sub