Consulting

Results 1 to 6 of 6

Thread: Change all text that has a specific font

  1. #1
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    3
    Location

    Change all text that has a specific font

    I have some documents which have rubrics in a special font. In WordPerfect I have a macro which searches for that font and changes it to red text. I would like to do the same thing in PowerPoint. I have done quite a lot of scripting but am new to VBA. So far, I have only written one VBA macro. I goes through a PowerPoint slide show and changes all the titles to the same font face, size, and color. Mostly it was cut and pasted from material I found online but I think I understand the workflow. I do not know how to parse the text within a TextFrame or determine the font at the cursor.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    You really need to explain further BUT this would search for a font by name (Aharoni in this case) and color it red. It will NOT search in tables / charts. USE on a copy!

    Sub red_Text()
    Dim osld As Slide
    Dim oshp As Shape
    Dim L As Long
    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    If oshp.HasTextFrame Then
    If oshp.TextFrame.HasText Then
    For L = 1 To oshp.TextFrame.TextRange.Runs.Count
    If oshp.TextFrame.TextRange.Runs(L).Font.Name = "Aharoni" Then
    oshp.TextFrame.TextRange.Runs(L).Font.Color.RGB = vbRed
    End If
    Next L
    End If
    End If
    Next oshp
    Next osld
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    3
    Location

    [SOLVED] Change all text that has a specific font

    Thanks I figured it out after looking at this post by MHamid:
    {Sorry I can't seem to post the link}

    Sub Color_Rubrics()
    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.Name = "LSBSymbol" Then
                                .Runs(x).Font.Color.RGB = RGB(255, 0, 0)
                            End If
                        Next x
                    End With
                End If
            End If
        Next oShp
    Next oSld
    End Sub

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    That look just like my code.

    here's the lnk to MHamid too
    http://www.vbaexpress.com/forum/show...ace-Text-Color
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    3
    Location
    Thanks, I found a solution before I saw your post. It is very similar. As I said, most of it I got from MHamid. There are probably not a whole lot of ways to do this.

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Yes I know I just recognise my code style! I think this is where I originally posted back in 2011
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

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