Search code examples
vbapowerpointshapes

I want to change all shape borders in slide


Dim oSh As Shape

For i =1 To 5

I gave here For loop to go and find each shape

With oSh
.Fill.Visible = False
.Line.BackColor.RGB = RGB(255, 255, 0)
Set oSh = Nothing
End With
Next i

But seems like does not work properly

End Sub

Solution

  • Change this:

    With oSh
    .Fill.Visible = False
    .Line.BackColor.RGB = RGB(255, 255, 0)
    Set oSh = Nothing
    End With
    

    To this, assuming that you want to work with the currently selected slide or slides:

    Sub ChangeTheShapes()
    ' Make sure you select one or more
    ' slides (in the thumbnail pane or slide sorter)
    ' before running this.
    
        Dim osh As Shape
        Dim oSl As Slide
        
        ' in case a shape doesn't have a fill
        On Error Resume Next
        
        For Each oSl In ActiveWindow.Selection.SlideRange
            For Each osh In oSl.Shapes
                With osh
                  .Fill.Visible = False
                  .Line.BackColor.RGB = RGB(255, 255, 0)
                End With
            Next   ' Shape
        Next 'slide
        
    End Sub
    

    You can also delete anything you've done with the variable i since you're not using it for anything.