View Single Post
 
Old 06-24-2017, 06:52 AM
leaning leaning is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jan 2011
Posts: 19
leaning is on a distinguished road
Default

I attempted code based on other code I found, but it fails on the highlight line (I'm using PP 2013), and then I'm not exactly sure if ^p will find the non-printing backwards P paragraph symbol. Anyone know how to fix this?

Code:
Option Explicit

Sub HighlightKeywords()
'https://stackoverflow.com/questions/15844903/find-and-highlight-text-in-ms-powerpoint
    Dim sld As Slide
    Dim shp As Shape
    Dim txtRng As TextRange, rngFound As TextRange
    Dim i As Long, n As Long
    Dim TargetList
    TargetList = Array(" ", "^p") '~~>  Array of terms to search for
    For Each sld In Application.ActivePresentation.Slides  '~~> Loop through each slide
        For Each shp In sld.Shapes  '~~> Loop through each shape
            If shp.HasTextFrame Then '~~> Check if it has text
                Set txtRng = shp.TextFrame.TextRange
                    For i = 0 To UBound(TargetList)
                    Set rngFound = txtRng.Find(TargetList(i)) '~~> Find the text
                    Do While Not rngFound Is Nothing '~~~> If found
                        n = rngFound.Start + 1 '~~> Set the marker so that the next find starts from here
                            If rngFound.Font.Bold = msoTrue And rngFound.Font.Color = vbRed Then
                            rngFound.Font2.Highlight.RGB = RGB(255, 255, 0) 'yellow
                            End If
                        Set rngFound = txtRng.Find(TargetList(i), n) '~~> Find Next instance
                    Loop
                    Next
            End If
        Next
    Next
    MsgBox "Done"
End Sub
Reply With Quote