From: a1k1do via OfficeKB.com on 1 May 2010 13:29 I have a simple vba script: With SlideShowWindows(1).View .GotoSlide (40) End With End Sub Is there anything i can add to this to show a message or goto the previous slide if slide 40 is the current slide or slide 40 has been deleted (meaning there are less than 40 slides). Thanks in advance for any coaching. -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/powerpoint/201005/1
From: broro183 on 2 May 2010 10:37 hi, Maybe something like this...? I wasn't exactly sure what you want to happen if there are fewer than 40 slides so you'll probably have to change it a bit. VBA Code: -------------------- Sub test1() Const TrgtSlideInd As Long = 40 'Target Slide Index Dim NumOfSlides As Long Dim CurSlideInd As Long 'Current Slide Index NumOfSlides = ActivePresentation.Slides.Count With ActivePresentation.SlideShowWindow.View CurSlideInd = .Slide.SlideIndex Select Case True Case (CurSlideInd = TrgtSlideInd) 'already here, do nothing 'or, do you want to choose the previous slide...? .GotoSlide (CurSlideInd - 1) Case NumOfSlides >= TrgtSlideInd .GotoSlide (40) Case Else 'choose the last slide .GotoSlide (NumOfSlides) End Select End With End Sub -------------------- hth Rob -- broro183 Rob Brockett. Always learning & the best way to learn is to experience... ------------------------------------------------------------------------ broro183's Profile: http://www.thecodecage.com/forumz/member.php?u=333 View this thread: http://www.thecodecage.com/forumz/showthread.php?t=200002 http://www.thecodecage.com/forumz
From: a1k1do via OfficeKB.com on 3 May 2010 00:52 Hi Rob Thank's thats perfect and thanks for commenting also. Helps on the learning curve. Just splendid broro183 wrote: >hi, > >Maybe something like this...? >I wasn't exactly sure what you want to happen if there are fewer than 40 >slides so you'll probably have to change it a bit. > >VBA Code: >-------------------- > > > >Sub test1() > Const TrgtSlideInd As Long = 40 'Target Slide Index > Dim NumOfSlides As Long > Dim CurSlideInd As Long 'Current Slide Index > > NumOfSlides = ActivePresentation.Slides.Count > With ActivePresentation.SlideShowWindow.View > CurSlideInd = .Slide.SlideIndex > Select Case True > Case (CurSlideInd = TrgtSlideInd) > 'already here, do nothing > 'or, do you want to choose the previous slide...? > .GotoSlide (CurSlideInd - 1) > Case NumOfSlides >= TrgtSlideInd > .GotoSlide (40) > Case Else > 'choose the last slide > .GotoSlide (NumOfSlides) > End Select > End With > End Sub > > >-------------------- > >hth >Rob > -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/powerpoint/201005/1
From: David Marcovitz on 3 May 2010 10:03 The previous poster gave one approach. The Select/Case statement is often a good choice. I find the standard If statement to be conceptually easier. Sub Goto40OrNot() If ActivePresentation.SlideShowWindow.View.Slide.Slide Index = 40 Then 'Is the current slide 40 ActivePresentation.SliideShowWindow.View.Previous 'go to previous slide Else If ActivePresentation.Slides.Count < 40 Then ActivePresentation.SlideShowWindow.View.Previous 'go to previous Else 'we're not on 40 and there are at least 40 slides ActivePresentation.SlideShowWindow.View.GotoSlide 40 ' go to slide 40 End If End Sub On 5/1/10 1:29 PM, a1k1do via OfficeKB.com wrote: > I have a simple vba script: > > With SlideShowWindows(1).View > .GotoSlide (40) > End With > End Sub > > Is there anything i can add to this to show a message or goto the previous > slide > if > slide 40 is the current slide > or > slide 40 has been deleted (meaning there are less than 40 slides). > > Thanks in advance for any coaching. > -- David M. Marcovitz Author of _Powerful PowerPoint for Educators_ http://www.PowerfulPowerPoint.com/ Microsoft PowerPoint MVP Associate Professor, Loyola University Maryland
From: broro183 on 3 May 2010 12:44 hi all, *a1k1do*, Thanks for the feedback - I'm pleased I could help :) *David*, I'm new to ppt VBA coding*, as you may have guessed from my "CurSlide -1" instead of ".previous" - thanks, I'll remember that for the future :) *(I'm more experienced in Excel's VBA) I agree that the If statement is conceptually easier, esp in comparison to "flipping a select Case statement on its head" like I did. I think I did it that way because the concept was on my mind as I'd just been looking at some similar Excel VBA code. Just out of curiosity, In Excel's VBA I'll try to group anything I can using a With statement, but I notice that you haven't grouped anything. Is this just your personal preference or are there some limitations to With statements in PPT's VBA? Thanks Rob -- broro183 Rob Brockett. Always learning & the best way to learn is to experience... ------------------------------------------------------------------------ broro183's Profile: http://www.thecodecage.com/forumz/member.php?u=333 View this thread: http://www.thecodecage.com/forumz/showthread.php?t=200002 http://www.thecodecage.com/forumz
|
Next
|
Last
Pages: 1 2 Prev: How do you play a power point presentation inside the window only Next: giveawayoftheday |