PDA

View Full Version : Hide non-highlighted text on a Microsoft Word document including text boxes



nachobo
08-30-2021, 02:17 AM
Hello everyone,
(https://stackoverflow.com/posts/68955505/timeline)

I would like to hide the text that's is not highlighted in my document.

I've already code the part where I can't do it on "normal" text, but I got textboxes with highlighted text inside and I cant access to them.
I've try to do some research to get inside this text boxes but nothing works.

This is what I've done until now:


Sub Hide_onCondition_RSO()
'
' Hide_RSO Macro
'
'
Dim eShape As Word.Shape

For Each eShape In ActiveDocument.Shapes
If eShape.Type = msoTextBox Then
With eShape.TextFrame.TextRange.Find
.Text = ""
.ClearFormatting
.Format = True
.Highlight = False
.Replacement.Text = ""
.Replacement.ClearFormatting
.Replacement.Font.Hidden = True
.Execute Replace:=wdReplaceAll
End With
End If
Next eShape
End Sub



When I try to loop around shapes, and try to access to the text frame of the shape to see if the text is highlighted or no, that the macro doesn't find them because maybe they are in a group (?).


https://i.stack.imgur.com/GogXT.png

Do you have any ideas ?
Thank you !