Consulting

Results 1 to 6 of 6

Thread: Find and Replace Text Color

  1. #1
    VBAX Regular
    Joined
    Oct 2015
    Posts
    21
    Location

    Find and Replace Text Color

    Hello,

    Ihave the following code that will change some text color from blue to black.However, it is missing the blue text from tables, charts, etc. How can Ienhance the code below to include tables, charts, etc? Also, how can I enhancethe table to also include finding and replacing red text to black text?

    Sub BlackDeletei()
    Dim oSld As slide
    Dim oShp As shape
    Dim x As Long
    For Each oSld In ActivePresentation.Slides
        For Each oShp In oSld.Shapes
            If oShp.HasTextFrame Then
                If oShp.TextFrame.HasText Then
                    With oShp.TextFrame.TextRange
                        For x = .Runs.Count To 1 Step -1
                            If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Then
                                .Runs(x).Font.Color.RGB = RGB(0, 0, 0)
                            End If
                        Next x
                    End With
                End If
            End If
        Next oShp
    Next oSld
    
    End Sub
    Thank you
    Last edited by Aussiebear; 04-24-2023 at 05:05 AM. Reason: Edited the font size

  2. #2
    VBAX Regular
    Joined
    Oct 2015
    Posts
    21
    Location
    Hello,

    I figured it out.

    Thank you

  3. #3
    Hi,

    Could you please past the code what you figured it out. It is very useful for me.

    Thanks

  4. #4
    VBAX Regular
    Joined
    Oct 2015
    Posts
    21
    Location
    My apologies. I thought I posted the functioning code.
    Sub ReplaceBlueRedToBlack()
    Dim oSld As Slide
    Dim oShp As Shape
    Dim oTbl As Table
    Dim lRow As Integer
    Dim lCol As Integer
    Dim x As Long
    For Each oSld In ActivePresentation.Slides
        For Each oShp In oSld.Shapes
            If oShp.HasTextFrame Then
                If oShp.TextFrame.HasText Then
                    With oShp.TextFrame.TextRange
                        For x = .Runs.Count To 1 Step -1
                            If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Or .Runs(x).Font.Color.RGB = RGB(255, 0, 0) Then
                                .Runs(x).Font.Color.RGB = RGB(0, 0, 0)
                            End If
                        Next x
                    End With
                End If
            End If
            If oShp.HasTable Then
            Set oTbl = oShp.Table
                With oTbl
                    For lRow = 1 To .Rows.Count
                        For lCol = 1 To .Columns.Count
                            With oTbl.Cell(lRow, lCol).Shape.TextFrame.TextRange
                                For x = .Runs.Count To 1 Step -1
                                    If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Or .Runs(x).Font.Color.RGB = RGB(255, 0, 0) Then
                                        .Runs(x).Font.Color.RGB = RGB(0, 0, 0)
                                    End If
                                Next x
                            End With
                        Next lCol
                    Next lRow
                End With
            End If
        Next oShp
    Next oSld
    End Sub

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Just another way to do it:

    Assuming you are using a version after 2007 it is good practice to use TextFrame2 to be able to use the new formatting if required.

    Sub ReplaceBlueRedToBlack()Dim oSld As Slide
    Dim oshp As Shape
    Dim oTbl As Table
    Dim iRow As Integer
    Dim iCol As Integer
    For Each oSld In ActivePresentation.Slides
        For Each oshp In oSld.Shapes
        Select Case oshp.HasTable
        Case Is = True
        With oshp.Table
        For iRow = 1 To .Rows.Count
                        For iCol = 1 To .Columns.Count
                        Call fixSHAPE(.Cell(iRow, iCol).Shape)
                        Next iCol
                        Next iRow
                        End With
        Case Is = False
         Call fixSHAPE(oshp)
        End Select
        Next oshp
    Next oSld
    End Sub
    
    
    Sub fixSHAPE(oshp As Shape)
    Dim x As Long
    If oshp.HasTextFrame Then
                If oshp.TextFrame2.HasText Then
                    With oshp.TextFrame2.TextRange
                        For x = .Runs.Count To 1 Step -1
                            If .Runs(x).Font.Fill.ForeColor.RGB = RGB(0, 0, 255) Or .Runs(x).Font.Fill.ForeColor.RGB = RGB(255, 0, 0) Then
                                .Runs(x).Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
                            End If
                        Next x
                    End With
                End If
            End If
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    Thank you so much for your help this code is really helpful for me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •