Searching for and Selecting specific hidden text

M

MWK

I have a document that has multiple lines of hidden text. How do I select
just the text I want and make it visible? I've seen the code that will find
the text based on format but it seems the find command does not include
hidden text in its search.

Any help will be much appreciated.

Thanks!
 
G

Greg Maxey

Try toggling the display on and off in the code:

Sub ScratchMacro()
Dim rngstory As Word.Range
Set rngstory = ActiveDocument.Range
ActiveWindow.View.ShowHiddenText = True
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = False
.MatchWholeWord = True
.Wrap = wdFindContinue
.Font.Hidden = True
.Text = "Your text"
.Replacement.Text = "^&"
.Replacement.Font.Hidden = False
.Execute Replace:=wdReplaceAll
End With
ActiveWindow.View.ShowHiddenText = False

End Sub
 
M

MWK

Thank you very much. I've been hitting the wall on this one for the last
two days. Hopefully this is the last wall. :)

Thanks again!

Michael
 
K

Klaus Linke

Hi Michael,

Searching for .Font.Hidden=True is buggy, though. If the beginning of your document is hidden and/or you use hidden styles, it'll not work properly.
The work-around is to use .Font.Hidden=wdToggle.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top