macro to remove hidden text

D

davidh

Greetings MS WORD folk,
when I record a new macro to remove hidden text in WORD 2003 it does
not work.
text of macro as created by the record macro is as follows
============
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/27/2007 by user
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
=========
any and all advice greatly appreciated.
many thanks Davidh
 
G

Graham Mayor

The macro recorder does not record formatting associated with the replace
tool so your macro finds nothing and replaces it with nothing. You must add
the required font formatting manually eg

Sub Macro1()
Dim sView As Boolean
sView = ActiveWindow.View.ShowHiddenText
ActiveWindow.View.ShowHiddenText = True
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
'********************
.Font.Hidden = True
'********************
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.View.ShowHiddenText = sView
End Sub

The macro also ensures that the hidden text is displayed before deleting it
regardless of whether it was displayed previously, then resets the display
to its previous state viz-a-viz hidden text.
http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

davidh

Thank You Graham Mayor
that was exactly the information that I was seeking,
many thanks
Davidh
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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