Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General PowerPoint Questions / July 2007

Tip: Looking for answers? Try searching our database.

Using VBA to navigate slides in a presentation?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
flying_pig - 09 Jul 2007 11:50 GMT
As a newbie I assume this is a trivial question but I can't get the syntax
right.

I have a number of slides with several drawing objects on each.

I have a simple menu as part of the presentation screen (as a master slide)
to launch macros that among other things, each needs to show a specific slide
(I have named each slide) and the objects on them are selectively made
visible/not visible.

All I am seeking is a line or two of VBA that will enable random access to
slides in my slide show.

I show/hide shapes using syntax like this:

  ActivePresentation.Slides(1).Shapes("MyShape").Visible = msoTrue
  ActivePresentation.Slides(1).Shapes("MyShape").Visible = msoFalse

but have not suceeded in selecting the required slide ( and showing it) yet.

Any tips would be appreciated

Thanks

Bob L
David M. Marcovitz - 09 Jul 2007 15:06 GMT
When you say "random," do you really mean random, or do you mean that you
want to be able to click on a button to take you to a specific slide? If
you just want to go to a specific slide, then you can do something like:

ActivePresentation.SlideShowWindow.View.GotoSlide 5

That takes you to slide 5 (change the 5 to whatever you want). If you
truly mean random (or pseudo-random since I said "truly" and there might
be some mathematicians listening), then you are talking about something a
bit more complicated. You might look at Exampels 8.16 and 8.17 on my site
(http://www.PowerfulPowerPoint.com/) to get one idea of how to move to a
random slide.

--David

Signature

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/

=?Utf-8?B?Zmx5aW5nX3BpZw==?= <flyingpig@discussions.microsoft.com> wrote
in news:984FE90B-26A9-4DB1-A13D-6F835CD097F7@microsoft.com:

> As a newbie I assume this is a trivial question but I can't get the
> syntax right.
[quoted text clipped - 22 lines]
>
> Bob L
flying_pig - 12 Jul 2007 10:50 GMT
David,

I meant radom in the RAM sense i.e. user has free choice rather than
sequential.

I will try your code but I think I had problems with that.  I also wish to
refer to the slides by the name I have given them.

Thanks

> When you say "random," do you really mean random, or do you mean that you
> want to be able to click on a button to take you to a specific slide? If
[quoted text clipped - 37 lines]
> >
> > Bob L
flying_pig - 12 Jul 2007 11:06 GMT
David,

I have now checked slide access using the suggested code and that works fine
using the numerical position of the slide as the value in the code e.g. 5 for
the fifth slide. However I wanted to goto my named slide e.g. "MyNamedslide"

Thank you

> David,
>
[quoted text clipped - 47 lines]
> > >
> > > Bob L
Steve Rindsberg - 12 Jul 2007 16:09 GMT
> I have now checked slide access using the suggested code and that works fine
> using the numerical position of the slide as the value in the code e.g. 5 for
> the fifth slide. However I wanted to goto my named slide e.g. "MyNamedslide"

You can do that as well.  This function returns the slide index of any named
slide (or 0 if there's no slide by that name):

Function IndexOfSlideNamed(sSlideName As String) As Long
' Returns the slide index of the named slide or 0 if slide not present

   Dim oSl As Slide
   Dim lTemp As Long
   
   For Each oSl In ActivePresentation.Slides
       If UCase(oSl.Name) = UCase(sSlideName) Then
           lTemp = oSl.SlideIndex
       End If
   Next
   
   IndexOfSlideNamed = lTemp
   
End Function

To test it:

Sub TestMe()
   MsgBox IndexOfSlideNamed("Bubba")
End Sub

To use it, you'd do something like:

Dim lTemp as Long
lTemp = IndexOfSlideNamed("Bubba")
If lTemp > 0 Then  ' you know the slide exists
 ActivePresentation.SlideShowWindow.View.GotoSlide lTemp
Else
 ' do whatever you need to do if the slide's not there
End If

> > > ActivePresentation.SlideShowWindow.View.GotoSlide 5
> > >
[quoted text clipped - 33 lines]
> > > >
> > > > Bob L

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
David M. Marcovitz - 12 Jul 2007 16:38 GMT
Steve's code is the complete version with all the bells and whistles
(mainly error checking). I usually use something like:

ActivePresentation.SlideShowWindow.View.GotoSlide _
  ActivePresentation.Slides("MyNamedSlide").SlideIndex

It's simple, but if you screw up (like trying to go to a named slide that
doesn't exist), it won't do anything.

--David

Signature

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/

>> I have now checked slide access using the suggested code and that
>> works fine using the numerical position of the slide as the value in
[quoted text clipped - 82 lines]
> PPTools:  www.pptools.com
> ================================================
Steve Rindsberg - 13 Jul 2007 14:44 GMT
> Steve's code is the complete version with all the bells and whistles
> (mainly error checking). I usually use something like:
[quoted text clipped - 4 lines]
> It's simple, but if you screw up (like trying to go to a named slide that
> doesn't exist), it won't do anything.

And as long as you test the presentation beforehand to make sure it all works,
I'd go with yours, especially if there are lots of slides in the show.  It'll
be marginally faster, I'd bet.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
flying_pig - 15 Jul 2007 15:40 GMT
David,

This is even better for my purpose as I keep a list of all slide and object
names and have a macro to read/write/edit them if needed.

> Steve's code is the complete version with all the bells and whistles
> (mainly error checking). I usually use something like:
[quoted text clipped - 93 lines]
> > PPTools:  www.pptools.com
> > ================================================
flying_pig - 13 Jul 2007 10:04 GMT
Steve,

Thanks for the Function it works as needed.

> > I have now checked slide access using the suggested code and that works fine
> > using the numerical position of the slide as the value in the code e.g. 5 for
[quoted text clipped - 78 lines]
> PPTools:  www.pptools.com
> ================================================
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.