VBA - Count slides in a PPT file that is not open

P

PHason

Through VBA, how would I go about getting the count of slides for a
PPT file that isn't open?

Essentially this:

ActivePresentation.Slides.Count

but for a file instead of the currently running slideshow.

I just can't get the syntax correct, so if any one could stear me in
the right direction, that would be great.

Thanks!
 
P

PHason

Thank you Austin.

And thanks, John for the sample code.

I'm almost getting it, but I get a "Runtime error '13' -- type
mismatch" when I run it. I'm guessing I need to use a different object
than Presentations, but I'm not sure what. It stops right on the "set
opres=Presentations.Open(filepath)" line, but when I End the code the
presentation being referenced is opened by the code, yet there is that
error.

I'm using PowerPoint 2003 if that makes a difference.

Any suggestions.

Thanks a bunch.
 
T

T Lavedas

Thank you Austin.

And thanks, John for the sample code.

I'm almost getting it, but I get a "Runtime error '13' -- type
mismatch" when I run it. I'm guessing I need to use a different object
than Presentations, but I'm not sure what. It stops right on the "set
opres=Presentations.Open(filepath)" line, but when I End the code the
presentation being referenced is opened by the code, yet there is that
error.

I'm using PowerPoint 2003 if that makes a difference.

Any suggestions.

Thanks a bunch.

No, the Open method must take a Presentations object as its
expression. The problem lies somewhere else. I suppose it could be
in how you have dimensioned the opres variable, if you did dimension
it.

I think you need to post some actual code to get a correct diagnosis.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
P

PHason

No, the Open method must take a Presentations object as its
expression.  The problem lies somewhere else.  I suppose it could be
in how you have dimensioned the opres variable, if you did dimension
it.

I think you need to post some actual code to get a correct diagnosis.

Tom Lavedas
===========http://members.cox.net/tglbatch/wsh/- Hide quoted text -

- Show quoted text -

That is a good idea. I had taken it down to the simplest form to try
to determine where the issue is, but I still run into the same
problem. I've tried both a UNC path and a local path to the file and I
get the same result.

Here is the code:

====================
Public Sub Test()

Dim opres As Presentations
Set opres = Presentations.Open("\\Ph-tv\PH-TV\Installs.ppt")
opres.Close

End Sub
====================

When I run it, I first get an error that states "Compile error: Method
or data member not found" for the "opres.Close" line.

If I remark out the "opres.Close" line, then I get the "Runtime error
'13': Type mismatch" error on the "Set opres = Presentations.Open("\
\Ph-tv\PH-TV\Installs.ppt")" line. Like I stated before, an additional
session of PowerPoint does start and the file is opened, but the code
stops running at that line.

Thanks.
 
T

T Lavedas

That is a good idea. I had taken it down to the simplest form to try
to determine where the issue is, but I still run into the same
problem. I've tried both a UNC path and a local path to the file and I
get the same result.

Here is the code:

====================
Public Sub Test()

Dim opres As Presentations
Set opres = Presentations.Open("\\Ph-tv\PH-TV\Installs.ppt")
opres.Close

End Sub
====================

When I run it, I first get an error that states "Compile error: Method
or data member not found" for the "opres.Close" line.

If I remark out the "opres.Close" line, then I get the "Runtime error
'13': Type mismatch" error on the "Set opres = Presentations.Open("\
\Ph-tv\PH-TV\Installs.ppt")" line. Like I stated before, an additional
session of PowerPoint does start and the file is opened, but the code
stops running at that line.

Thanks.

Take the 's' off the end of Presentations. The type that is returned
is a single Presentation, not the Presentations collection type.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
P

PHason

Take the 's' off the end of Presentations.  The type that is returned
is a single Presentation, not the Presentations collection type.

Tom Lavedas
===========http://members.cox.net/tglbatch/wsh/- Hide quoted text -

- Show quoted text -

Tom, thanks a bunch, that did the trick! I was getting tripped up that
the type is "Presentation", but then the function is
"Presentations.Open". Again, thanks a ton.
 
S

Shyam Pillai

You can get the slide count without using PowerPoint. Search for DSOFile. It
is a microsoft component which allows you to retrieve document properties.
Sample code is included in the download.

Regards,
Shyam Pillai

Image Importer Wizard
http://skp.mvps.org/iiw.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top