Question

I have tried to create this script that would create 10 empty slides, but it doesn't work for some reason:

Sub CreatingSlides()
    Dim oPresentation As Presentation
    Set oPresentation = ActivePresentation
    Dim oSlide As Slide
    Dim oSlides As SlideRange
    Dim oShape As Shape
    Dim slideNumber As Integer
    Dim myindex As Integer

    Set myindex = 1
    ActivePresentation.Slides.add(Index:=myindex, Layout:=ppLayoutBlank).Select
    For myindex = 1 To 10
        myindex = myindex + 1
        ActivePresentation.Slides.add(Index:=myindex, Layout:=ppLayoutBlank).Select
    Next myindex
End Sub

What have I done wrong here? Maybe my loop here is missing something?

Was it helpful?

Solution

First:

  Set myindex = 1 

should be:

  myindex = 1

Set is for object references. Let is for values and is usually implied but you could also use:

  Let myindex = 1

which has the same affect.

Second, loose the line

  myindex = myindex + 1

That's what the For/Next is doing for you. You might have some different behaviour expectations still so try this and we can go from there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top