Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem looping through PowerPoint Slides

Status
Not open for further replies.

jgillin

Programmer
Oct 22, 2003
82
US
Hi,
We have a Visual Basic application that uses OLE automation to control PowerPoint (loop through slides, extract information, etc). For some reason, the looping through the slides portion of the code is throwing an error (but only on my computer -- other peoples computers don't seem to be having this issue).
The code in question is the following (code has been shortened for conciseness):

MsgBox ppt.ActivePresentation.Slides.count
Dim oSl As Object
For Each oSl In ppt.ActivePresentation.Slides

Next

The statement that has the Message Box works fine, and gives the correct number of slides of the presentation that was opened.
The "For Each" line throws an error which is:
"Property let procedure not defined and property get procedure did not return an object".

-- The weirdest part of this is that it seems to work fine on other peoples computers, but something is causing an issue on mine (though it used to work in the past). I haven't worked on this application in quite a while, so I can't determine what has been recently changed on this computer.

-- Does anyone have any thoughts or suggestions on how to determine the underlying issue with this?

Thanks for any thoughts.

 
Just a thought, may be being too simplistic.
But are the references the same on all machines?

Barney
 
I'm not 100% sure, but I don't think it has to do with references because I can take the compiled exe, and run it on other computers without a problem, but not on mine. All computers have MS Office 2003.

Here's another piece of the puzzle.
I opened the source code on another computer -- using the same exact set of files and set a breakpoint right before the error occurs, and compared the variables in the "locals" window - specifically the subproperties of the ActivePresentation.Slides property (technically ppt.ActivePresentation.Slides in my app), and oddly enough, the subproperties of "Slides" that show up for the good computer are different than the subproperties that show up on the "bad" computer.
The good computer shows the following "subproperties" of the Slides property:
-- Application
-- Count
-- Parent
-- Item1
-- Item2

-- This is a PowerPoint file (ppt) with 2 slides on it, and Item1 and Item2 represent the individual slides.
-- Now, on the computer where I'm getting the errors, I see the following subproperties of "Slides" (at the same breakpoint in the application)
-- Application
-- Count
-- Parent

There are no entries for the slides: Item1, Item2.
I'm thinking there's some sort of configuration issue somewhere on the "bad" computer. I tried uninstalling / reinstalling MS Office, but to no avail.

Unfortunately, I'm still having issues using this piece of information to determine what's occurring.

Does this strike any bells with anyone?

Thanks for any suggestions.
 
Check the code. There could be a presentation without slides. This happens for instance after:
Code:
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Set ppApp = New PowerPoint.Application
ppApp.Visible = True
Set ppPres = ppApp.Presentations.Add
or deleting all slides. Such presentation still exists and can be active, but the collection of slides is empty.

combo
 
Thanks for the reply. Unfortunately, none of the code is this application creates any presentations. It's simply for opening / extracting. The weird thing here is that it does recognize the slide "count" and the slide count property returns the correct number of slides, but for some reason, it never creates reference variables to those slides (on the "bad" computer). In other words, the Item1, Item2, etc never get created as slide references. Today, I thought that maybe some background service is turned off, but I checked against the "good" computer and everything seems to be the same. Also, I tried explicitly setting the version when creating the PowerPoint object as such:
Set ppt = CreateObject("PowerPoint.Application.11")
but unfortunately, no luck here either.
I'm also thinking I'm going to need an OS re-install (that something somewhere was corrupted at some point).
If anyone else has any additional thoughts, please chime in. Thanks for all the suggestions.
 
The 'Locals' window is a good starting point for analysis. Assuming you are in break mode, do you have the powerpoint app visible? What is active presentation name? Is it the same as in 'Locals'? Are both have slides?
Have you tried to reference powerpoint library and use early binding?

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top