Search code examples
vbapowerpoint

PowerPoint Macro: Change font size based on colour of font


I want to write a powerpoint macro where if my text colour is blue it will change the text size in shape. Not sure if it is possible? Appreciate your comments on the same


Solution

  • Sub thing()
    Dim oSh As Shape
    Dim oSl As Slide
    Dim RGBColor As Long
    
    ' Change this as needed
    RGBColor = RGB(255, 0, 0)
    
    For Each oSl In ActivePresentation.Slides
    For Each oSh In oSl.Shapes
        If oSh.HasTextFrame Then
            If oSh.TextFrame.HasText Then
                With oSh.TextFrame.TextRange
                    If .Font.Color.RGB = RGB(255, 0, 0) Then
                      .Font.Size = 12
                    End If
                End With
            End If
        End If
    Next
    Next
    End Sub
    

    Or to change just the selected shape:

    Sub ChangeFontByColor()
    Dim oSh As Shape
    Dim RGBColor As Long
    
    ' Change this as needed
    RGBColor = RGB(255, 0, 0)
      Set oSh = ActiveWindow.Selection.Shaperange(1)    
        If oSh.HasTextFrame Then
            If oSh.TextFrame.HasText Then
                With oSh.TextFrame.TextRange
                    If .Font.Color.RGB = RGB(255, 0, 0) Then
                      .Font.Size = 12
                    End If
                End With
            End If
        End If
    End Sub