VBA code to open and close series of PowerPoint files now having issues

rolmstead

New Member
Joined
Jan 16, 2012
Messages
8
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:

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
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Is closing the powerpoint item(1) sufficient to release the memory used by the objects?
Try setting that item to Nothing and see if that works.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top