0

I have the following loop, which is meant to create a triangle on slides 2 to 4.

For i = 2 To 4

With ActivePresentation.Slides(i)

    Dim tri As Shape
    Set tri = ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeRightTriangle, 886, 0, 74, 74)

End With
Next i

The code works, but because I'm calling ActiveWindow, the loop creates the triangle 3 times on the same slide (the one I run the macro from) rather than on 3 slides.

I know this is the problem, but I don't know how to modify that part of the code to fix it. What is required instead?

2 Answers 2

2

You need to use the iterated presentation slide:

For i = 2 To 4

  With ActivePresentation.Slides(i)

    Dim tri As Shape
    Set tri = .Shapes.AddShape(msoShapeRightTriangle, 886, 0, 74, 74)

  End With

Next i
Sign up to request clarification or add additional context in comments.

Comments

1

fast solution

For i = 2 To 4

With ActivePresentation.Slides(i)

    Dim tri As Shape
    Set tri = ActivePresentation.Slides(i).Shapes.AddShape(msoShapeRightTriangle, 886, 0, 74, 74)

End With
Next i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.