Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

106 views
Skip to first unread message

PHason

unread,
May 27, 2008, 2:58:20 PM5/27/08
to
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!

John Wilson

unread,
May 27, 2008, 3:35:06 PM5/27/08
to
AFAIK you would need to open the file, count the slides and close it again

set opres=Presentations.Open(filepath)
Islides=opres.Slides.Count
opres.Close
--
-------------------------------------------
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk

Austin Myers

unread,
May 27, 2008, 3:56:49 PM5/27/08
to
As far as I know there is no way to do so without open the file.


Austin Myers
Microsoft PowerPoint MVP Team

Creator of PFCPro, PFCMedia and PFCExpress
http://www.playsforcertain.com


"PHason" <jko...@palmerhamilton.com> wrote in message
news:c5265b3f-d028-4eac...@w7g2000hsa.googlegroups.com...

PHason

unread,
May 28, 2008, 10:21:44 AM5/28/08
to
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.

On May 27, 2:35 pm, John Wilson <john AT technologytrish.co DOT uk>
wrote:


> AFAIK you would need to open the file, count the slides and close it again
>
> set opres=Presentations.Open(filepath)
> Islides=opres.Slides.Count
> opres.Close
> --
> -------------------------------------------
> Amazing PPT Hints, Tips and Tutorials
>

> http://www.PPTAlchemy.co.ukhttp://www.technologytrish.co.uk


> email john AT technologytrish.co.uk
>
>
>
> "PHason" wrote:
> > 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!- Hide quoted text -
>
> - Show quoted text -

T Lavedas

unread,
May 28, 2008, 10:41:37 AM5/28/08
to

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/

PHason

unread,
May 28, 2008, 11:09:54 AM5/28/08
to
>
> 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 Lavedas

unread,
May 28, 2008, 11:34:10 AM5/28/08
to
On May 28, 11:09 am, PHason <jko...@palmerhamilton.com> wrote:
> > 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.

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

PHason

unread,
May 28, 2008, 11:45:29 AM5/28/08
to
On May 28, 10:34 am, T Lavedas <tglba...@cox.net> wrote:
> On May 28, 11:09 am, PHason <jko...@palmerhamilton.com> wrote:
>
>
>
>
>
> > > 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/-Hidequoted 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.
>
> 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.

Shyam Pillai

unread,
May 28, 2008, 4:41:44 PM5/28/08
to
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


"PHason" <jko...@palmerhamilton.com> wrote in message
news:c5265b3f-d028-4eac...@w7g2000hsa.googlegroups.com...

0 new messages