我想允许用户通过文本框输入 RGB 颜色并传递该变量以更改所有形状的颜色。我写了一个循环,它会查看形状名称的最后 2 个字符,以确定它是否应该更改为主要颜色或次要颜色。
这是最新版 Office 365 的 powerpoint。
我已经尝试了以下代码。我收到类型不匹配或无效参数错误:
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