Word Macro - Hide all non-highlighted texts

Hello Team,

I am looking for an word macro to hide all non-highlighted and yellow highlighted text from multiple word documents.
Can you please suggest or any reference to do this.

Thanks,
Shail
LVL 3
Shailesh ShindeLocalization Engineering & AutomationAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
GrahamSkanConnect With a Mentor RetiredCommented:
This version is slighly shorter and doesn't require the specification of the highlight colours that are to stay visible.
Sub ShowOtherHighlights()
    Dim rng As Word.Range
    
    Set rng = ActiveDocument.Range
    rng.Font.Hidden = True 'hide all text
    With rng.Find
        .Highlight = True
        Do While .Execute
            If rng.HighlightColorIndex <> wdYellow Then
                rng.Font.Hidden = False
            End If
         Loop
    End With
End Sub

Open in new window

0
 
GrahamSkanRetiredCommented:
Can you clarify what you want to remain visible, please?
0
 
Shailesh ShindeLocalization Engineering & AutomationAuthor Commented:
Hi,

Visible will be only green highlighted contents from the files.

Thanks,
Shail
0
 
GrahamSkanRetiredCommented:
Try this. Note more than one HighLight colours can be kept visible (line 10)
Sub ShowGreen()
    Dim rng As Word.Range
    
    Set rng = ActiveDocument.Range
    rng.Font.Hidden = True 'hide all text
    With rng.Find
      .Highlight = True
      Do While .Execute
        Select Case rng.HighlightColorIndex
            Case wdBrightGreen ', wdYellow ( any other colours to remain visible)
                rng.Font.Hidden = False
        End Select
       Loop
    End With
End Sub

Open in new window

0
 
Shailesh ShindeLocalization Engineering & AutomationAuthor Commented:
Thanks a lot! This works perfectly with slightly changed requirement.
0
All Courses

From novice to tech pro — start learning today.