在同一 Powerpoint 演示文稿的多张幻灯片中将特定文本颜色替换为其他颜色

在同一 Powerpoint 演示文稿的多张幻灯片中将特定文本颜色替换为其他颜色

我正在做一个演示文稿,里面有 200 多张幻灯片。每张幻灯片都包含多行。每张幻灯片的每一行中,都有一部分文本以蓝色突出显示。我想将蓝色更改为其他颜色。

我希望这个变化能够反映在所有幻灯片中,这意味着特定的颜色应该被我的新颜色所取代,并且它不应该影响其他文本颜色,因为它是其他颜色,因为我想强调这一点。

简而言之,在所有幻灯片中用其他颜色替换文本特定部分的特定颜色。

答案1

以下是 PowerPoint 常见问题解答http://www.pptfaq.com

问题

您的许多幻灯片中都有很多文本。其中一些文本已设置为您现在需要更改的颜色。这会有所帮助。

Option Explicit

Sub ChangeTextColors()

    Dim oSl As Slide
    Dim oSh As Shape
    Dim lCol As Long
    Dim lRow As Long
    Dim x As Long

    Dim lOldColor As Long
    Dim lNewColor As Long

    ' EDIT THESE TO THE COLORS YOU WANT TO CHANGE FROM and TO
    lOldColor = RGB(100, 200, 100)
    lNewColor = RGB(200, 100, 200)

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes

            If oSh.HasTextFrame Then
                If oSh.TextFrame.HasText Then
                    Call ChangeTextRange(oSh.TextFrame, lOldColor, lNewColor)
                End If
            End If

            If oSh.HasTable Then
                With oSh.Table
                    For lCol = 1 To .Columns.Count
                        For lRow = 1 To .Rows.Count
                            Call ChangeTextRange(.Cell(lRow, lCol).Shape.TextFrame, lOldColor, lNewColor)
                        Next
                    Next
                End With
            End If

' this part is commented out because PPT 's buggy and ... sorry ... haven't quite figured it out yet:
'            If oSh.HasSmartArt Then
'                With oSh.SmartArt
'                    For x = 1 To .Nodes.Count
'                        Call ChangeTextRange(.Nodes(x).TextFrame2, lOldColor, lNewColor)
'                    Next
'                End With
'            End If

            If oSh.HasChart Then
                ' You're on your own, my friend
            End If

        Next
    Next

End Sub

Sub ChangeTextRange(oTextFrame As Object, lOldColor As Long, lNewColor As Long)

    Dim x As Long

    With oTextFrame.TextRange
        For x = 1 To .Runs.Count
            If .Runs(x).Font.Color.RGB = lOldColor Then
                .Runs(x).Font.Color.RGB = lNewColor
            End If
        Next
    End With

End Sub

相关内容