PC Review


Reply
Thread Tools Rate Thread

count number of slides?

 
 
Geoff Cox
Guest
Posts: n/a
 
      12th Jun 2006
Hello,

I have hundreds of presenations and would like to know the total
number of slides - can anyone point me at macro code for this?

Thanks

Geoff
 
Reply With Quote
 
 
 
 
Geoff Cox
Guest
Posts: n/a
 
      12th Jun 2006
On Mon, 12 Jun 2006 09:12:52 +0100, Geoff Cox
<(E-Mail Removed)> wrote:

I am trying the following code - it is the sub MyMacro which I need a
little help with.

I can get the number of slides for each presentation but how do I get
the total number of slides for all presentations?

I guessing I need something like

slidesPerPresentation = ActivePresentation.Slides.Count

totalSlides = totalSlides + slidesPerPresentaion

but not clear how to do this.

Thanks

Geoff




Sub check_each_slide_for_buttons()

Dim rayFileList() As String
Dim FolderPath As String
Dim FileSpec
Dim strTemp As String
Dim x As Long

FolderPath = "c:\test\activities\" ' Note: MUST end in \
FileSpec = "*.ppt"

ReDim rayFileList(1 To 1) As String
strTemp = Dir$(FolderPath & FileSpec)
While strTemp <> ""
rayFileList(UBound(rayFileList)) = FolderPath & strTemp
ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
String
strTemp = Dir
Wend

If UBound(rayFileList) > 1 Then
For x = 1 To UBound(rayFileList) - 1
Call MyMacro(rayFileList(x))

Next x
End If

End Sub

Sub MyMacro(strMyFile As String)

Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation

MsgBox = "number of slides = " & ActivePresentation.Slides.Count


oPresentation.Close


End With




End Sub














 
Reply With Quote
 
Brian Reilly, MVP
Guest
Posts: n/a
 
      12th Jun 2006


Geoff

You need to declare a variable that has global scope (read up on Scope
in Help)

Put at the top of the module before any Sub routines the following
Public lSlideTotal as Long

Then modify MyMacro to add the counter

> With oPresentation
>
> MsgBox = "number of slides = " & ActivePresentation.Slides.Count
>
>
> oPresentation.Close

'Next line adds the running total. Starts at 0 on first pressie
lSlideCount = lSlideCount + activepresentation.slides.count
>
>End With



Brian Reilly, MVP

On Mon, 12 Jun 2006 13:29:35 +0100, Geoff Cox
<(E-Mail Removed)> wrote:

>On Mon, 12 Jun 2006 09:12:52 +0100, Geoff Cox
><(E-Mail Removed)> wrote:
>
>I am trying the following code - it is the sub MyMacro which I need a
>little help with.
>
>I can get the number of slides for each presentation but how do I get
>the total number of slides for all presentations?
>
>I guessing I need something like
>
>slidesPerPresentation = ActivePresentation.Slides.Count
>
>totalSlides = totalSlides + slidesPerPresentaion
>
>but not clear how to do this.
>
>Thanks
>
>Geoff
>
>
>
>
>Sub check_each_slide_for_buttons()
>
> Dim rayFileList() As String
> Dim FolderPath As String
> Dim FileSpec
> Dim strTemp As String
> Dim x As Long
>
> FolderPath = "c:\test\activities\" ' Note: MUST end in \
> FileSpec = "*.ppt"
>
> ReDim rayFileList(1 To 1) As String
> strTemp = Dir$(FolderPath & FileSpec)
> While strTemp <> ""
> rayFileList(UBound(rayFileList)) = FolderPath & strTemp
> ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
>String
> strTemp = Dir
> Wend
>
> If UBound(rayFileList) > 1 Then
> For x = 1 To UBound(rayFileList) - 1
> Call MyMacro(rayFileList(x))
>
> Next x
> End If
>
>End Sub
>
>Sub MyMacro(strMyFile As String)
>
> Dim oPresentation As Presentation
> Set oPresentation = Presentations.Open(strMyFile)
>
> With oPresentation
>
> MsgBox = "number of slides = " & ActivePresentation.Slides.Count
>
>
> oPresentation.Close
>
>
>End With
>
>
>
>
>End Sub
>
>
>
>
>
>
>
>
>
>
>
>
>

 
Reply With Quote
 
Steve Rindsberg
Guest
Posts: n/a
 
      12th Jun 2006
In article <(E-Mail Removed)>, Geoff Cox wrote:
> On Mon, 12 Jun 2006 09:12:52 +0100, Geoff Cox
> <(E-Mail Removed)> wrote:


Try rewriting MyMacro as a function instead of a sub:
I'm also renaming it to make its use more obvious

Function CountSlides(strMyFile As String) as Long
' Open a presentation named in strMyFile
' Return the number of slides in the presentation

Dim oPresentation As Presentation

Set oPresentation = Presentations.Open(strMyFile)

CountSlides = oPresentation.Slides.Count

oPresentation.Close

End Sub

Now in your main code you can use something like:

' assuming you Dim lTotalSlides as Long:
lTotalSlides = lTotalSlides + CountSlides(strMyFile)



>
> I am trying the following code - it is the sub MyMacro which I need a
> little help with.
>
> I can get the number of slides for each presentation but how do I get
> the total number of slides for all presentations?
>
> I guessing I need something like
>
> slidesPerPresentation = ActivePresentation.Slides.Count
>
> totalSlides = totalSlides + slidesPerPresentaion
>
> but not clear how to do this.
>
> Thanks
>
> Geoff
>
> Sub check_each_slide_for_buttons()
>
> Dim rayFileList() As String
> Dim FolderPath As String
> Dim FileSpec
> Dim strTemp As String
> Dim x As Long
>
> FolderPath = "c:\test\activities\" ' Note: MUST end in \
> FileSpec = "*.ppt"
>
> ReDim rayFileList(1 To 1) As String
> strTemp = Dir$(FolderPath & FileSpec)
> While strTemp <> ""
> rayFileList(UBound(rayFileList)) = FolderPath & strTemp
> ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
> String
> strTemp = Dir
> Wend
>
> If UBound(rayFileList) > 1 Then
> For x = 1 To UBound(rayFileList) - 1
> Call MyMacro(rayFileList(x))
>
> Next x
> End If
>
> End Sub
>
> Sub MyMacro(strMyFile As String)
>
> Dim oPresentation As Presentation
> Set oPresentation = Presentations.Open(strMyFile)
>
> With oPresentation
>
> MsgBox = "number of slides = " & ActivePresentation.Slides.Count
>
>
> oPresentation.Close
>
> End With
>
> End Sub
>


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      12th Jun 2006
On Mon, 12 Jun 2006 10:36:22 -0400, "Brian Reilly, MVP"
<(E-Mail Removed)> wrote:

>
>
>Geoff
>
>You need to declare a variable that has global scope (read up on Scope
>in Help)
>
>Put at the top of the module before any Sub routines the following
>Public lSlideTotal as Long
>
>Then modify MyMacro to add the counter
>
>> With oPresentation
>>
>> MsgBox = "number of slides = " & ActivePresentation.Slides.Count
>>
>>
>> oPresentation.Close

>'Next line adds the running total. Starts at 0 on first pressie
>lSlideCount = lSlideCount + activepresentation.slides.count
>>
>>End With


Brian,

I seme to have used your suggests correctly in that the code works but
if I run it successively the total keeps adding to itself - where do I
prevent this?

Thanks

Geoff


Public lSlideCount As Long

Sub count_slides()

Dim rayFileList() As String
Dim FolderPath As String
Dim FileSpec
Dim strTemp As String
Dim x As Long


FolderPath = "c:\test\activities\" ' Note: MUST end in \
FileSpec = "*.ppt"


' Fill the array with files that meet the spec above
ReDim rayFileList(1 To 1) As String
strTemp = Dir$(FolderPath & FileSpec)
While strTemp <> ""
rayFileList(UBound(rayFileList)) = FolderPath & strTemp
ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As
String
strTemp = Dir
Wend

If UBound(rayFileList) > 1 Then
For x = 1 To UBound(rayFileList) - 1
Call MyMacro(rayFileList(x))

Next x
End If

MsgBox "total = " & lSlideCount

End Sub

Sub MyMacro(strMyFile As String)


Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)


With oPresentation

lSlideCount = lSlideCount + ActivePresentation.Slides.Count


oPresentation.Close


End With




End Sub




























 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      12th Jun 2006
On Mon, 12 Jun 2006 11:00:05 EDT, Steve Rindsberg
<(E-Mail Removed)> wrote:

>In article <(E-Mail Removed)>, Geoff Cox wrote:
>> On Mon, 12 Jun 2006 09:12:52 +0100, Geoff Cox
>> <(E-Mail Removed)> wrote:

>
>Try rewriting MyMacro as a function instead of a sub:
>I'm also renaming it to make its use more obvious
>
>Function CountSlides(strMyFile As String) as Long
>' Open a presentation named in strMyFile
>' Return the number of slides in the presentation
>
> Dim oPresentation As Presentation
>
> Set oPresentation = Presentations.Open(strMyFile)
>
> CountSlides = oPresentation.Slides.Count
>
> oPresentation.Close
>
>End Sub
>
>Now in your main code you can use something like:
>
>' assuming you Dim lTotalSlides as Long:
>lTotalSlides = lTotalSlides + CountSlides(strMyFile)



Steve,

I have not used a function before with VBA - how does it work? Do I
call a function as with a sub or is this different?

Cheers

Geoff

 
Reply With Quote
 
David M. Marcovitz
Guest
Posts: n/a
 
      12th Jun 2006
Functions are just like Subs that return values. That's why the function
has a type (the As Long at the end of the first line). Call it just like
a Sub, but then do something with the result that is returned. The result
that is returned is whatever the name of the Function is set to in the
function (in this case, that is the line: CountSlides = ...)
--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/

Geoff Cox <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> On Mon, 12 Jun 2006 11:00:05 EDT, Steve Rindsberg
> <(E-Mail Removed)> wrote:
>
>>In article <(E-Mail Removed)>, Geoff Cox

wrote:
>>> On Mon, 12 Jun 2006 09:12:52 +0100, Geoff Cox
>>> <(E-Mail Removed)> wrote:

>>
>>Try rewriting MyMacro as a function instead of a sub:
>>I'm also renaming it to make its use more obvious
>>
>>Function CountSlides(strMyFile As String) as Long
>>' Open a presentation named in strMyFile
>>' Return the number of slides in the presentation
>>
>> Dim oPresentation As Presentation
>>
>> Set oPresentation = Presentations.Open(strMyFile)
>>
>> CountSlides = oPresentation.Slides.Count
>>
>> oPresentation.Close
>>
>>End Sub
>>
>>Now in your main code you can use something like:
>>
>>' assuming you Dim lTotalSlides as Long:
>>lTotalSlides = lTotalSlides + CountSlides(strMyFile)

>
>
> Steve,
>
> I have not used a function before with VBA - how does it work? Do I
> call a function as with a sub or is this different?
>
> Cheers
>
> Geoff
>
>


 
Reply With Quote
 
Steve Rindsberg
Guest
Posts: n/a
 
      12th Jun 2006
In article <(E-Mail Removed)>, Geoff Cox wrote:
> >Try rewriting MyMacro as a function instead of a sub:
> >I'm also renaming it to make its use more obvious
> >
> >Function CountSlides(strMyFile As String) as Long
> >' Open a presentation named in strMyFile
> >' Return the number of slides in the presentation
> >
> > Dim oPresentation As Presentation
> >
> > Set oPresentation = Presentations.Open(strMyFile)
> >
> > CountSlides = oPresentation.Slides.Count
> >
> > oPresentation.Close
> >
> >End Sub
> >
> >Now in your main code you can use something like:
> >
> >' assuming you Dim lTotalSlides as Long:
> >lTotalSlides = lTotalSlides + CountSlides(strMyFile)

>
> Steve,
>
> I have not used a function before with VBA - how does it work? Do I
> call a function as with a sub or is this different?


What David said. But you call it as per my example:

' assuming you Dim lTotalSlides as Long:
lTotalSlides = lTotalSlides + CountSlides(strMyFile)


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      12th Jun 2006
On Mon, 12 Jun 2006 08:39:26 -0700, "David M. Marcovitz"
<(E-Mail Removed)> wrote:

>Functions are just like Subs that return values. That's why the function
>has a type (the As Long at the end of the first line). Call it just like
>a Sub, but then do something with the result that is returned. The result
>that is returned is whatever the name of the Function is set to in the
>function (in this case, that is the line: CountSlides = ...)
>--David



Thanks David.

Cheers

Geoff
 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      12th Jun 2006
On Mon, 12 Jun 2006 14:12:55 EDT, Steve Rindsberg
<(E-Mail Removed)> wrote:

>In article <(E-Mail Removed)>, Geoff Cox wrote:
>> >Try rewriting MyMacro as a function instead of a sub:
>> >I'm also renaming it to make its use more obvious
>> >
>> >Function CountSlides(strMyFile As String) as Long
>> >' Open a presentation named in strMyFile
>> >' Return the number of slides in the presentation
>> >
>> > Dim oPresentation As Presentation
>> >
>> > Set oPresentation = Presentations.Open(strMyFile)
>> >
>> > CountSlides = oPresentation.Slides.Count
>> >
>> > oPresentation.Close
>> >
>> >End Sub
>> >
>> >Now in your main code you can use something like:
>> >
>> >' assuming you Dim lTotalSlides as Long:
>> >lTotalSlides = lTotalSlides + CountSlides(strMyFile)

>>
>> Steve,
>>
>> I have not used a function before with VBA - how does it work? Do I
>> call a function as with a sub or is this different?

>
>What David said. But you call it as per my example:
>
>' assuming you Dim lTotalSlides as Long:
>lTotalSlides = lTotalSlides + CountSlides(strMyFile)


Steve,

OK - I see.

Thanks

Geoff


>
>
>-----------------------------------------
>Steve Rindsberg, PPT MVP
>PPT FAQ: www.pptfaq.com
>PPTools: www.pptools.com
>================================================
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Count for INDIVIDUAL slides?? Casabee Microsoft Powerpoint 1 6th Mar 2009 10:20 PM
Adding Total Number of slides to the page number field in the footer J Microsoft Powerpoint 3 2nd Oct 2008 01:14 AM
Re: Count that will display the number for each record in the count increment. Sylvain Lafontaine Microsoft Access ADP SQL Server 0 12th Jul 2008 04:25 PM
VBA - Count slides in a PPT file that is not open PHason Microsoft Powerpoint 8 28th May 2008 09:41 PM
How do I put slide number of total number of slides in a master? =?Utf-8?B?Q2hyaXMgb2YgdGhlIE5vcnRo?= Microsoft Powerpoint 1 5th Oct 2005 03:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:30 PM.