Word 2003 Find/Replace Doesn't Ignore Deleted Text

J

John Sharp

I'm trying to write a macro that finds & replaces several things all in one
batch. Track changes needs to be on.

The problem is that the "finds" also see and act on deleted text. How can I
run a find and replace that ignores the deleted text? I know this was a
problem in Word 97 because I found a KB article on it. Surely they fixed it
by now?

I have tried limiting finds for black text or font style normal...that
doesn't work.
 
R

Russ

John,
I'm trying to write a macro that finds & replaces several things all in one
batch. Track changes needs to be on.

The problem is that the "finds" also see and act on deleted text.

A little bit of semantics here ;-)
The text is still there and only "marked" for deletion by an overlay with
actual deletion pending until deletion change is accepted. That's why the
find function still sees it. If you select a piece of "marked" text and
bring up the font format dialog box, you'll see that the font format still
shows it as it was before being marked for deletion. It's like the dialog
box is not aware of the other "dimensional" marking overlay. The find dialog
box must not see it either.
 
T

Tony Jollans

To make F&R ignore deleted text you need to make it hidden, something like
this ...

Dim DeletedTextOption As WdDeletedTextMark

' Save the current user setting
DeletedTextOption = Options.DeletedTextMark
' Override it with Hidden
Options.DeletedTextMark = wdDeletedTextMarkHidden
' Make sure hidden text is not looked at
ActiveDocument.Range.TextRetrievalMode.IncludeHiddenText = False

' Do your Replace here

' Reset to user's option, saved above
Options.DeletedTextMark = DeletedTextOption
 
R

Russ

To make F&R ignore deleted text you need to make it hidden, something like
this ...

Dim DeletedTextOption As WdDeletedTextMark

' Save the current user setting
DeletedTextOption = Options.DeletedTextMark
' Override it with Hidden
Options.DeletedTextMark = wdDeletedTextMarkHidden
' Make sure hidden text is not looked at
ActiveDocument.Range.TextRetrievalMode.IncludeHiddenText = False

' Do your Replace here
Also an important distinction is that Selection.Find does not seem to work
with TextRetrievalMode.
You must use Range.Find. Something like this macro will delete everything
except hidden text.:

Sub Macro13()
Dim aRange As Range

ActiveDocument.Range.TextRetrievalMode.IncludeHiddenText = False
Set aRange = ActiveDocument.Content

With aRange.Find
.Font.hidden = False
.Text = ""
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With

End Sub
 
R

Russ

Oops,
Also an important distinction is that Selection.Find does not seem to work
with TextRetrievalMode.
Selection.Find does work as long the Show/Hide Button isn't hiding the text
like:

ActiveWindow.ActivePane.View.ShowAll = False

Before doing a selection find. That doesn't seem to matter when using a
range find.
 

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