Problem with MS Word 2002 macro to remove hidden text

E

Ermine

I recorded a macro by completing the steps of Find Hidden text format and
leaving the Replace with field empty. The steps work, but the macro does not.
Does anyone know why the macro does not work? Thanks.
 
A

Anne Troy

This macro (recorded) works for me, Ermine:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/30/2004 by Anne Troy
'
Selection.Find.ClearFormatting
With Selection.Find.Font
.Hidden = True
End With
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^?"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

**** Hope it helps! ****

~Dreamboat
Excel VBA Certification Coming Soon!
www.VBAExpress.com/training/
Brainbench Word Test Developer 2000,2002,2003
********************************
 
E

Ermine

Anne,

In a new test document I created, your macro works. But in the document I
was originally using (which is an example of the documents I need to use the
macro on), your macro replaced all the regular text with hidden text rather
than removing all hidden text and having the regular text remain. There must
be something in these documents I am unaware of. They are engineering
specifications and could have contained some form of metadata because most of
the hidden text that remained after running the macro was not visible
previously. And yes, show-hide was turned on. Thanks for your help.
 
H

Helmut Weber

Hi Ermine,
sometimes another method works,
which doesn't mean, that there is anything wrong with Anne's code.
If both methods fail, then document may be corrupted in a way,
or, what's more likely, I'd say, is wasn't created by Word, but
converted from another application.
---
Sub Test009()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Resetsearch
ActiveWindow.View.ShowHiddenText = True
With rDcm.find
.Text = ""
.Font.Hidden = True
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
Resetsearch
End Sub
Sub Resetsearch()
With Selection.find
.Parent.Collapse
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub
 
E

Ermine

As it turns out both yours and Anne's code works; however, when either macro
is run, the insertion point MUST be located within the Normal text, NOT the
Hidden text! That's not a problem; I'm happy with the solution. Thanks to
both of you!

Ermine
 

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