PDA

View Full Version : [SOLVED:] Change colour of specific shape on 1 slide (not all slides)



Jack.Conroy
12-30-2015, 09:18 PM
Hi,
I am new to VBA and looking for some assistance on a code to change the colour of a specific shape on a powerpoint slide (but not all slides - just the active slide I am on). The current shape is a ShapeSnipRectangle (Left:=515, Top:=0, Width:=205, Height:=80) and is coloured RGB(255, 255, 102).

I have the below code but this changes all shapes in all slides not just the current slide.


Sub Slide_Updated()
Dim oSh As Shape
Dim oS1 As Slide
For Each oS1 In ActivePresentation.Slides
For Each oSh In oS1.Shapes
If oSh.Fill.ForeColor.RGB = RGB(255, 255, 102) Then
oSh.Fill.ForeColor.RGB = RGB(179, 222, 104)
End If
Next oSh
Next oS1
End Sub

Thanks,
Jack.

Bob Phillips
12-31-2015, 04:16 AM
Is this what you are looking for?


Sub Slide_Updated()
Dim oSh As Shape
Dim oS1 As Slide
Dim idx As Long

idx = ActiveWindow.View.Slide.SlideIndex
With ActivePresentation.Slides(idx)
With .Shapes("myShape")
If .Fill.ForeColor.RGB = RGB(255, 255, 102) Then
.Fill.ForeColor.RGB = RGB(179, 222, 104)
End If
End With
End With
End Sub

John Wilson
01-01-2016, 01:59 PM
Or maybe


Sub Slide_Updated()

Dim osld As Slide
Dim oshp As Shape
Set osld = ActiveWindow.Selection.SlideRange(1)
For Each oshp In osld.Shapes
If oshp.Fill.ForeColor.RGB = RGB(255, 255, 102) Then
oshp.Fill.ForeColor.RGB = RGB(179, 222, 104)
End If
Next oshp

End Sub