-1

When trying to execute the following:

Dim lCurrentSlide As Long
' Get the SlideID of the slide currently in view
lCurrentSlide = SlideShowWindows(1).View.Slide.SlideNumber

I get this:

Microsoft Visual Basic run-time error

Yesterday the code worked fine. Today - not so much.
Microsoft Visual Basic for Applications 7.1.1128

I copied some code from the internet to print one slide.
It worked fine yesterday.
I renamed all but the first slide in the deck.
It hasn't worked since.

The error message reads:

Run-time error '-2147188160 (800248240)': SlideShowWindows (unknown member) : Integer out of range. 1 is not in the valid range of 1 to 0.

GSerg
  • 76,472
  • 17
  • 159
  • 346
Tjingles
  • 1
  • 2
  • 1 is indeed not in the (empty) range of 1-0. It would be in the range of 0-1 though. What is your `SlideShowWindows.Count`? – GSerg Feb 05 '23 at 19:09
  • Safe to assume it is 0. – Hans Passant Feb 05 '23 at 19:15
  • 1
    Here's how to enumerate slides in PP ... https://stackoverflow.com/questions/34399343/automatic-slide-numbering-in-powerpoint-using-vba – user10186832 Feb 05 '23 at 20:15
  • Use this method to get the first SlideShowWindow ... https://learn.microsoft.com/en-us/office/vba/api/powerpoint.slideshowview.first – user10186832 Feb 05 '23 at 20:17
  • 1
    There are three different properties that you're confusing. SlideID is a number assigned when a slide is created and that never changes, even if the slide is moved within the presentaiton. SlideNumber is the number that appears in slide number placeholders but because the user can choose to start slide numbering at something other than zero, it doesn't necessarily indicate the ordinal position of the slide. You want SlideIndex here. – Steve Rindsberg Feb 05 '23 at 20:19
  • SlideID doesn't change as long as the slide is in existence. However, if a slide is deleted, that SlideID may be reused to identify a newly created slide ... https://microsoft.public.powerpoint.narkive.com/rt2P0Ixl/vba-ppt-slide-value – Tjingles Feb 06 '23 at 16:28
  • Good point @Tjingles. But in this case, SlideIndex is what's needed. In fact, SlideID is just a misnomer in the comment; not even used. – Steve Rindsberg Feb 06 '23 at 16:36

1 Answers1

0

I modified the code:

lCurrentSlide = SlideShowWindows(1).View.Slide.SlideNumber

to read:

    On Error Resume Next
    Set currentSlide = Application.ActiveWindow.View.Slide
    Set currentSlide = ActivePresentation.SlideShowWindow.View.Slide
    lCurrentSlide = currentSlide.slideIndex
    on Error GoTo 0

And now the procedure executes as expected whether I'm in design mode or slideshow mode.

I studied all the articles posted in the comments as well as some insights from pages found from searches on variations of my original question.

Hopefully soon I will understand more about how to work with slides in vba. I'm pretty good with Excel vba - and I know vba is vba but it's not, really.

Oran G. Utan
  • 455
  • 1
  • 2
  • 10
Tjingles
  • 1
  • 2