Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Change one text color to another

Problem

You have lots of text in lots of slides. Some of it has been set to a color that you now need to change. This will help.

Solution

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

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2015 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Change one text color to another
http://www.pptfaq.com/FAQ01222-Change-one-text-color-to-another.htm
Last update 19 August, 2015
Created: 19 August, 2015