Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

macro to remove hidden text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
davidh - 27 Sep 2007 06:54 GMT
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
Graham Mayor - 27 Sep 2007 07:27 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Greetings MS WORD folk,
> when I record a new macro to remove hidden text in WORD 2003 it does
[quoted text clipped - 25 lines]
> any and all advice greatly appreciated.
> many thanks Davidh
davidh - 27 Sep 2007 11:53 GMT
Thank You Graham Mayor
that was exactly the information that I was seeking,
many thanks
Davidh
Graham Mayor - 27 Sep 2007 14:16 GMT
You are welcome :)

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thank You Graham Mayor
> that was exactly the information that I was seeking,
> many thanks
> Davidh
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.