PDA

View Full Version : [SOLVED:] Change all text that has a specific font



AllenM
08-27-2018, 11:02 AM
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.

John Wilson
08-27-2018, 11:36 AM
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

AllenM
08-27-2018, 11:52 AM
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

John Wilson
08-27-2018, 12:20 PM
That look just like my code.

here's the lnk to MHamid too
http://www.vbaexpress.com/forum/showthread.php?62069-Find-and-Replace-Text-Color

AllenM
08-27-2018, 12:28 PM
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.

John Wilson
08-27-2018, 12:53 PM
Yes I know I just recognise my code style! I think this is where I originally posted back in 2011 (https://answers.microsoft.com/en-us/office/forum/office_2007-powerpoint/vba-powerpoint-how-to-change-the-font-color-from/eea94b23-0892-437f-b64c-6a240f000227)