0
votes

I'm working on a code snippet that will change the border of every shape in a given slide to a RGB color (black), and after that it is supposed to make only the activating shape (that was clicked on) turn red. The two parts of code work perfectly together, but when combined the part to turn a single shape red does no nothing.

Sub borderRecolorTest2(oSh As Shape) Dim selectionSlideNumber As Integer Dim chosenAvatar As Shape Dim thisSlide As Slide selectionSlideNumber = 5

Set thisSlide = activePresentation.Slides(selectionSlideNumber)

For Each oSh In thisSlide.Shapes oSh.Line.ForeColor.RGB = RGB(0, 0, 0) Next oSh MsgBox ("This works fine")

oSh.Line.ForeColor.RGB = RGB(255, 0, 0)

End Sub

The first part of the code works perfectly and changes all the shapes to black borders, and finishes the loop and goes to the msgBox with no issues.

The line after which should change just the activating shape does NOTHING, except when I take out the (properly working) for next loop, the same line of code works.

What gives?!

Thank you

1

1 Answers

0
votes

When you go through the loop, you’re replacing the passed-along shape (oSh) with the other shapes on the slide. Best way to get the desired effect would be to declare another variable (Dim oSh2 As Shape) and use that to run through the For loop.