Go to next tagged slide in array

G

Guest

I am trying to provide users a way to advance through only selected slides.
I have tagged the slides I want and created an array to hold the slide index
of those tagged slides. I'd like users to be able to click a button on an
add-in toolbar (which I have already created) and go to the next slide
specified in the array, kind of like the Find Next button.

I can create a procedure that advances through only my tagged slides, but I
don't know how to allow the user to stop and do some editing on each slide
before continuing. So it seems that I need a way for the user to go to the
first tagged slide, and then click to go to the next tagged slide when ready.
I'm stumped as to how to go about this.

Any suggestions?

Here's what I have so far...

Sub advanceSelectedSlides()
' Advance through ILO-Only slides only

Dim oPres As Presentation
Dim oSlides As Slides
Dim oSl As Slide
Dim numSlides As Integer
Dim i As Integer
Dim found As Integer
Dim counter As Integer
Dim arrSlides() As Variant

numSlides = oSlides.Count
found = 0
counter = 0

Set oPres = ActivePresentation
Set oSlides = oPres.Slides
ReDim arrSlides(1 To numSlides)

If IsViewTypeNormal <> True Then
ActiveWindow.ViewType = ppViewNormal
End If

ActiveWindow.View.GotoSlide (1)

For Each oSl In oSlides
With oSl.Tags
For i = 1 To .Count
If .Name(i) = "CONTEXT" And .Value(i) = "ILO Only" Then
found = found + 1
End If
If found <> 0 Then
counter = counter + 1
ReDim Preserve arrSlides(1 To counter)
arrSlides(counter) = .Parent.SlideIndex
Debug.Print .Parent.SlideIndex
found = 0
End If
Next 'i
End With
Next 'oSl

End Sub
 
S

Steve Rindsberg

I am trying to provide users a way to advance through only selected slides.
I have tagged the slides I want and created an array to hold the slide index
of those tagged slides. I'd like users to be able to click a button on an
add-in toolbar (which I have already created) and go to the next slide
specified in the array, kind of like the Find Next button.

I can create a procedure that advances through only my tagged slides, but I
don't know how to allow the user to stop and do some editing on each slide
before continuing. So it seems that I need a way for the user to go to the
first tagged slide, and then click to go to the next tagged slide when ready.
I'm stumped as to how to go about this.

Any suggestions?

Here's what I have so far...

Sub advanceSelectedSlides()
' Advance through ILO-Only slides only

Dim oPres As Presentation
Dim oSlides As Slides
Dim oSl As Slide
Dim numSlides As Integer
Dim i As Integer
Dim found As Integer
Dim counter As Integer
Dim arrSlides() As Variant

' I'm surprised this doesn't throw an error
' since oSlides doesn't refer to anything
numSlides = oSlides.Count

found = 0
counter = 0

Set oPres = ActivePresentation
Set oSlides = oPres.Slides

' this belongs here, I think:
numSlides = oSlides.Count
ReDim arrSlides(1 To numSlides)

If IsViewTypeNormal <> True Then
ActiveWindow.ViewType = ppViewNormal
End If

ActiveWindow.View.GotoSlide (1)

For Each oSl In oSlides
With oSl.Tags
For i = 1 To .Count
If .Name(i) = "CONTEXT" And .Value(i) = "ILO Only" Then
found = found + 1
End If
If found <> 0 Then
counter = counter + 1
ReDim Preserve arrSlides(1 To counter)
arrSlides(counter) = .Parent.SlideIndex
Debug.Print .Parent.SlideIndex
found = 0
End If
Next 'i
End With
Next 'oSl

End Sub


How about a slightly different approach:

Sub NextSlideInSequence()

Dim x As Long

' set the view as you did above

' Starting with the slide after the current slide,
' look ahead to find the next slide
' with the tag you're after:
For x = ActiveWindow.Selection.SlideRange(1).SlideIndex + 1 _
To ActivePresentation.Slides.Count

If ActivePresentation.Slides(x).Tags("GOTO") = "YES" Then
' found one, go there
ActiveWindow.View.GotoSlide _
(ActivePresentation.Slides(x).SlideIndex)
Exit Sub
End If

Next ' x

End Sub
 
G

Guest

Excellent! Much simpler and does what I need. Thank you for your help.

So now, what if I want to reverse it (go to previous tagged slide)?

I tried changing the For statement to:
For x = ActiveWindow.Selection.SlideRange(1).SlideIndex - 1 _
To ActivePresentation.Slides(1) Step -1

but I get:
Run-time error '438': "Object does not support this property or method".

What am I missing/doing wrong?
 
S

Steve Rindsberg

Excellent! Much simpler and does what I need. Thank you for your help.

So now, what if I want to reverse it (go to previous tagged slide)?

I tried changing the For statement to:
For x = ActiveWindow.Selection.SlideRange(1).SlideIndex - 1 _
To ActivePresentation.Slides(1) Step -1

but I get:
Run-time error '438': "Object does not support this property or method".

What am I missing/doing wrong?

At a guess, the error occurs when you're on slide 1?
Try starting at a later slide. If that fixes it, you'd just need to test

If ActiveWindow.Selection.SlideRange(1).SlideIndex > 1 Then
' the rest of the code here
End If
 
G

Guest

No, this error occurs regardless of the current slide index. (And I did try
adding the check for first slide anyway to see what would happen, but the
same error occurs.) Any other ideas?
 
S

Steve Rindsberg

This seems to get it done:

Sub PreviousSlideInSequence()

Dim x As Long

' set the view as you did above

Debug.Print ActiveWindow.Selection.SlideRange(1).SlideIndex
For x = ActiveWindow.Selection.SlideRange(1).SlideIndex - 1 To 1 Step -1

If ActivePresentation.Slides(x).Tags("GOTO") = "YES" Then
' found one, go there
ActiveWindow.View.GotoSlide _
(ActivePresentation.Slides(x).SlideIndex)
Exit Sub
End If

Next ' x
End Sub
 

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