Displaying 'Next' & 'Previous' Slide Titles In Captions/Textboxes/Labels

R

ryan.crowe

Hi All-
Good group here. I've found alot of useful stuff on it but I was
having trouble figuring this out:

Basically, beside my 'Next Slide' & 'Previous Slide' links, I want to
actually display the actual title of these slides. I am having trouble
figuring out the right strategy to go about this. After many
iterations, this is what I have, which I now can't even seem to trigger
but did work earlier (work meaning, it displayed the title in the label
after clicking the label). Here is what that code looks like:

PrevSlideTitle =
ActivePresentation.SlideShowWindow.Presentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex
- 1).Shapes.Title.TextFrame.TextRange.Text

NextSlideTitle =
ActivePresentation.SlideShowWindow.Presentation.Slides(SlideShowWindows(1).View.Slide.SlideIndex
+ 1).Shapes.Title.TextFrame.TextRange.Text

Label1 = PrevSlideTitle
Label2 = NextSlideTitle

I can figure out how to assign a label (or any other control for that
matter) these default values.

The problems I am having are:
- I can't get this to work properly when I put these label controls on
the slide master. They only seem to work when on individual slides
- They don't do anything until I click on the label
- They don't update when I move to the next or previous slide

Is there an easy way to do this? I am very new at PPT macros but have
VBA experience in Excel & Access.
 
D

David M. Marcovitz

I'm a bit short on time so this will be quick. First, you want to check
if there really is a next or previous slide, so you might want an If
statement to make sure that this isn't the first or last slide. You don't
need .SlideShowWindow.Presentation; ActivePresentation.Slides should be
sufficient.

Now you need to figure out two things. What is going to activate this,
and where is the text going to reside. It seems like you are trying to
put this in a shape on the Master slide that will be changed each time
you move from slide to slide. That is fine if you have the code to do
that and shapes on the master slide to hold the text.

You might also want to have an error check to make sure the next and
previous slides have titles (not all slides necessarily have titles).

To activiate your code, you will want the buttons (maybe you should make
them buttons and not labels) execute:

ActivePresentation.SlideShowWindow.View.Next

and then have it run the code to change the text (so you will be on the
correct slide). That is, one macro to move and change text. Otherwise, I
don't know how you are going to activate the change text code.

--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/

(e-mail address removed) wrote in
 
R

ryan.crowe

Hi David-
Thanks for the reply. I was able to get the captions to update by
running the code below in the OnSlideShowBegin & OnSlideShowNextSlide
subroutines of the 'EventGen' add-in/module. (OnSlideShowNextSlide
seems to run whether it is "Next" or "Previous" so it may more aptly be
called OnSlideShowChangeSlide)

First, PrevSlideTitle & NextSlideTitle are strings.

'This eliminates the first & last slides from normal label treatment
If SlideShowWindows(1).View.Slide.SlideIndex > 1 And _
SlideShowWindows(1).View.Slide.SlideIndex < _
ActivePresentation.Slides.Count Then
'Determines the previous slide's title (hence the -1)
PrevSlideTitle = ActivePresentation.Slides _
(SlideShowWindows(1).View.Slide.SlideIndex - 1) _
.Shapes.Title.TextFrame.TextRange.Text
'Determines the next slide's title (hence the +1)
NextSlideTitle = ActivePresentation.Slides _
(SlideShowWindows(1).View.Slide.SlideIndex + 1) _
.Shapes.Title.TextFrame.TextRange.Text
'Make sure the labels are visible
SlideMaster.lblPrevSlideTitle.Visible = True
SlideMaster.lblNextSlideTitle.Visible = True
'Apply the caption to the label (also append a <<< or >>>)
SlideMaster.lblPrevSlideTitle.Caption = "<<< " & PrevSlideTitle
SlideMaster.lblNextSlideTitle.Caption = NextSlideTitle & " >>>"
Else
'If last slide, hide the NextSlide label
If SlideShowWindows(1).View.Slide.SlideIndex =
ActivePresentation.Slides.Count Then
PrevSlideTitle = ActivePresentation.Slides _
(SlideShowWindows(1).View.Slide.SlideIndex - 1) _
.Shapes.Title.TextFrame.TextRange.Text
SlideMaster.lblPrevSlideTitle.Caption = "<<< " & PrevSlideTitle
SlideMaster.lblNextSlideTitle.Visible = False
End If
'If first slide, hide the PrevSlide label
If SlideShowWindows(1).View.Slide.SlideIndex = 1 Then
NextSlideTitle = ActivePresentation.Slides _
(SlideShowWindows(1).View.Slide.SlideIndex + 1) _
.Shapes.Title.TextFrame.TextRange.Text
SlideMaster.lblNextSlideTitle.Caption = NextSlideTitle & " >>>"
SlideMaster.lblPrevSlideTitle.Visible = False
End If

End If

And then to move the slideshow, I pasted some code suggested in another
thread to each label's click event (on the master slide):

Private Sub lblNextSlideTitle_Click()
With SlideShowWindows(1).View
.GotoSlide .CurrentShowPosition + 1
End With
End Sub
Private Sub lblPrevSlideTitle_Click()
With SlideShowWindows(1).View
.GotoSlide .CurrentShowPosition - 1
End With
End Sub
You might also want to have an error check to make sure the next and
previous slides have titles (not all slides necessarily have titles).

If a slide does not have a title, only the "<<<" or the ">>>" will show
up on the label but that will work for me.

I'm quite certain this code can be refined and I'm open to any that
wish to offer suggestions.
 

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