none
Powerpoint 2010 - vba - Slide scope RRS feed

  • Question

  • This should be simple for someone in the know. i am trying to get the current slide object, NOT number.

    I can find the slide number, however if i index the slides by the number, this causes an error. in my test case i had one slide and the function returned 1 for num. The slide is called "slide2" but i did not try to use this in the Slides object.

    But wait, there is more..
    If in the watch window i place  ActivePresentation.Slides(1) this works. I can see the slide content.

    I see plenty of examples which use range slide number, and "For Each osld In ActivePresentation.Slides"

    >> What am i missing to get access to the slide object ?

    Thanks

    ======================

    Dim osld As Slide
    Dim url As String
    Dim oCom As Comment
    Dim num As Integer

    num = ActivePresentation.SlideShowWindow.View.CurrentShowPosition

    osld = ActivePresentation.Slides(num)

    ' code does not pass here

     For Each oCom In osld.Comments
        Debug.Print oCom.Text
       url = oCom.Text
     Next oCom

    Thanks

    Monday, April 16, 2012 9:54 AM

Answers

  • Hi Greg,

    SlideShowWindow is a separate window. ActivePresentation is a valid object only when there is a presentation window with a open presentation.

    So, if you run this code from a PPS, it will fail.

    Also,

    > osld = ActivePresentation.Slides(num) will fail in vba since you get a object back so you have to use the Set statement.

    Set osld = ActivePresentation.Slides(num)

    You can also get to the presentation from the associated slide show window.

    for example. if SWnd is an object of SlideShowWindow type then you:

    Set osld = SWnd.Presentation.Slides(num)


    Regards, Shyam (http://skp.mvps.org)

    Monday, April 16, 2012 5:02 PM

All replies

  • Hi Greg,

    SlideShowWindow is a separate window. ActivePresentation is a valid object only when there is a presentation window with a open presentation.

    So, if you run this code from a PPS, it will fail.

    Also,

    > osld = ActivePresentation.Slides(num) will fail in vba since you get a object back so you have to use the Set statement.

    Set osld = ActivePresentation.Slides(num)

    You can also get to the presentation from the associated slide show window.

    for example. if SWnd is an object of SlideShowWindow type then you:

    Set osld = SWnd.Presentation.Slides(num)


    Regards, Shyam (http://skp.mvps.org)

    Monday, April 16, 2012 5:02 PM
  • Brilliant Shyam

    It worked. Any guideline you can offer when a set is needed, over a Dim ?

    I can see it is not needed if you use For Each

    Would this statement be close "set is needed when an object is referenced which is not one of the standard VBA data types" ?

    Thanks

    Tuesday, April 17, 2012 4:42 AM