If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
is there such a thing as an "if" statement for VBA please?
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.a...point/201005/1 |
#2
|
|||
|
|||
is there such a thing as an "if" statement for VBA please?
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.a...point/201005/1 |
#3
|
|||
|
|||
is there such a thing as an "if" statement for VBA please?
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.Slid e 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 |
#4
|
|||
|
|||
is there such a thing as an "if" statement for VBA please?
On 5/3/10 12:44 PM, broro183 wrote:
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 Personal preference. I group things with With statements when they make sense to me to do so. Too many With statements can get confusing. My book about PowerPoint VBA is geared toward a non-programmer audience so I usually aim for the conceptually easy even if it requires a few extra lines of code. If figure once someone moves beyond my book, they will develop their own coding style and learn all kinds of fun shortcuts. I do discuss With in the book but don't use it a lot. Additionally, for my previous answer, I was shooting from the hip and just typing what came to mind. As for CurSlide - 1 vs. .Previous, they actually work a bit differently. I believe CurSlide - 1 would be preferable in certain cases (especially if there are animations on the slide) while .Previous would be preferable in other cases (especially if there are hidden slides, maybe). --David -- David M. Marcovitz Author of _Powerful PowerPoint for Educators_ http://www.PowerfulPowerPoint.com/ Microsoft PowerPoint MVP Associate Professor, Loyola University Maryland |
#5
|
|||
|
|||
is there such a thing as an "if" statement for VBA please?
Well, my book pops up a lot, not because it is so good, but because it
is the only book that is dedicated to PowerPoint and VBA. I learned a lot of what is in the book right here in this newsgroup. I started by asking questions just like yours. If the boss is paying for the book, make him spring for a new copy. If you have to pay for it yourself, you can probably find a good deal on a used copy somewhere online. --David On 5/3/10 8:38 PM, broro183 wrote: hi David, Thanks for taking the time to give extra comments In the past week while researching ppt VBA your book has popped up a few times so I felt privileged to be involved in a thread where you were taking part. I'll find out over the next week or so just how much ppt work I'll be doing, and if it's going to add up, I'll see if I can get the boss to spring for a copy of your book Thanks Rob -- David M. Marcovitz Author of _Powerful PowerPoint for Educators_ http://www.PowerfulPowerPoint.com/ Microsoft PowerPoint MVP Associate Professor, Loyola University Maryland |
Thread Tools | |
Display Modes | |
|
|