首页 > 解决方案 > PPT VBA:将形状的强调色从一种主题颜色更改为另一种

问题描述

在 PPT VBA 中,我试图将文件中具有一种强调色的所有形状更改为另一种。我将此表单中的值提供给我的函数,但它不接受 OldColor 和 NewColor (themecolors) 作为 msoThemeColorAccent1,而是只接受 15。但是当我为 Fill.ForeColor.ObjectThemeColor 提供 msoThemeColorAccent1 时,它是可以接受的;从函数参数提供时不接受。有人可以提出解决方案吗?

这是我的表格: 形式

这些是我的代码块:

Private Sub cmdApply_Click()
    ReplaceColors cboOldColor.Value, cboNewColor.Value, cboOldTint.Text, cboNewTint.Text
End Sub

Sub ReplaceColors(OldColor As Variant, NewColor As Variant, OldTint As String, NewTint As String)

Dim i As Integer
Dim t As Integer
Dim oSld As Slide
Dim oShp As Shape
Dim x, y As Integer
Dim sBrightness
Dim oColor, nColor As ThemeColor
Dim oPP As Placeholders

    For Each oSld In ActivePresentation.Slides
        For Each oShp In oSld.Shapes
        'groups
          If oShp.Type = msoGroup Then
            'not groups
            Else
            With oShp 'other shapes
                ' Fill
                If .Fill.ForeColor.ObjectThemeColor = OldColor And .Fill.ForeColor.Brightness = OldTint Then
                        .Fill.ForeColor.ObjectThemeColor = NewColor
                        .Fill.BackColor.Brightness = NewTint
                End If

                ' Line
                If Not .Type = msoTable Then
                    If .Line.Visible = msoTrue Then
                        If .Line.ForeColor.ObjectThemeColor = OldColor And .Line.ForeColor.Brightness = OldTint Then
                            .Line.ForeColor.ObjectThemeColor = NewColor
                            .Line.ForeColor.Brightness = NewTint
                        End If
                    End If
                End If

                ' Text
                If .HasTextFrame Then
                    If .TextFrame.HasText Then
                        For y = 1 To .TextFrame.TextRange.Runs.count
                            If .TextFrame.TextRange.Runs(y).Font.Color.ObjectThemeColor = OldColor And .TextFrame.TextRange.Runs(y).Font.Color.Brightness = OldTint Then
                                .TextFrame.TextRange.Runs(y).Font.Color.ObjectThemeColor = NewColor
                                .TextFrame.TextRange.Runs(y).Font.Color.Brightness = NewTint
                            End If
                        Next
                    End If
                End If
            End With
            End If
    'oShp = Nothing
        Next oShp
    Next oSld
End Sub

标签: vbapowerpoint

解决方案


推荐阅读