Global Text Replacement

S

Steve Cronin

Folks;
What I want to do is to replace ALL occurrences of 'ABC' with 'XYZ'.
When I say ALL I mean ALL.
Occurrences in the mainDocument, Headers, Footers, TextBoxes, TextBoxes

in Headers, TextBoxes in Footers, Tables, Tables in Headers, and
Tables in Footers.

This on a Mac using 'do Visual Basic'. I've posted something in the
Mac forum and it seems as soon as I mention 'do Visual Basic' I get
pointed over here.

Anyway a simple Find/Replace doesn't scour the text of Tables nor
TextBoxes, though I've been told it should? could?

The code below does what I need except for one small thing ...
It doesn't work when I change the ActivePane to wdSeekPrimaryHeader or
wdSeekPrimaryFooter

So I've got it working MainDocument but the code goes brain-dead in
Headers and Footers...
Can someone point out what I need to do?

Also the code below has an odd nested construct. I found similar code
in the MSHelp files.
Can someone clarify why the For .. While Not .. Wend Next construct is

necessary?
The code doesn't work in I unwind it to a simple For Next loop.

Thanks!
Steve
_____________________________
ActiveDocument.ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
For Each myStoryRange In ActiveDocument.StoryRanges
myStoryRange.Find.Execute
FindText:="ABC",ReplaceWith:="XYZ",Replace:=wdReplaceAll
While Not (myStoryRange.NextStoryRange Is Nothing)
Set myStoryRange = myStoryRange.NextStoryRange
myStoryRange.Find.Execute FindText:=
"ABC",ReplaceWith:="XYZ",Replace:=wdReplaceAll
Wend
Next myStoryRange
 

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