I want to allow users to enter in a RGB color via a text box and pass that variable to change the colors of all shapes. I wrote a loop that would look at the last 2 characters of the shape name to determine if it should be changed to the primary or secondary color.
This is for powerpoint from the latest office 365.
I've tried the following codes. I am getting either an type mismatch or invalid argument error:
Dim osld As Slide
Dim oshp As Shape
Dim strMainColor As String, strSecondColor As String
'Set main color to default if users didn't enter a RGB value
If MainColor.Value = "" Then strMainColor = "73, 109, 164" Else strMainColor = MainColor.Value
'Set Secondary color to default if users didn't enter a RGB value
If SecondColor.Value = "" Then strSecondColor = "207, 203, 201" Else strSecondColor = SecondColor.Value
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If Right(oshp.Name, 2) = "_1" Then
'Main Color to all slides
oshp.Fill.ForeColor.RGB = "RGB(" + strMainColor + ")"
oshp.Fill.BackColor.RGB = "RGB(" + strMainColor + ")"
ElseIf Right(oshp.Name, 2) = "_2" Then
'Secondary Colors
oshp.Fill.ForeColor.RGB = "RGB(" + strSecondColor + ")"
oshp.Fill.BackColor.RGB = "RGB(" + strSecondColor + ")"
End If
Next oshp
Next osld
Dim osld As Slide
Dim oshp As Shape
Dim strMainColor As String, strSecondColor As String
'Set main color to default if users didn't enter a RGB value
If MainColor.Value = "" Then strMainColor = "73, 109, 164" Else strMainColor = MainColor.Value
'Set Secondary color to default if users didn't enter a RGB value
If SecondColor.Value = "" Then strSecondColor = "207, 203, 201" Else strSecondColor = SecondColor.Value
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If Right(oshp.Name, 2) = "_1" Then
'Main Color to all slides
oshp.Fill.ForeColor.RGB = RGB(strMainColor)
oshp.Fill.BackColor.RGB = RGB(strMainColor)
ElseIf Right(oshp.Name, 2) = "_2" Then
'Secondary Colors
oshp.Fill.ForeColor.RGB = RGB(strSecondColor)
oshp.Fill.BackColor.RGB = RGB(strSecondColor)
End If
Next oshp
Next osld