L
Leigh Hall
Hello,
I have built an application that will search through several word
documents, finding occurances of specified strings and replacing them
with others. The point of it is to be able to update multiple
documents with the same change without having to spend an age manually
editing.
I have got the code successfuly replacing all the free text within the
document, and also got the code to search through *some* of the text
boxes (with help from word.mvps.org!).
My problem is that some of the text box controls on the document seem
to be ignored by the code, and consequently the strings are not
replaced.
Has anybody encountered and/or (hopefully) solved this problem before?
Thanks in advance.
Leigh Hall
This is the code snippet that I am using for the main body search:
=====================================
With objWord.Selection.Range.Find
Do While .Execute(strFind, 0, , , , , 1, 1)
.Execute strFind, 0, , , , , 1, wdFindContinue, ,
strReplace, 1
DoEvents
iCnt = iCnt + 1
Loop
End With
=====================================
This is the code snippet that I took from mvps.org to search the text
boxes, etc:
=====================================
For Each styRange In objWordDoc.StoryRanges
Debug.Print styRange
With styRange.Find
.Text = strFind
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
iCnt = iCnt + 1
End With
Next styRange
======================================
I have built an application that will search through several word
documents, finding occurances of specified strings and replacing them
with others. The point of it is to be able to update multiple
documents with the same change without having to spend an age manually
editing.
I have got the code successfuly replacing all the free text within the
document, and also got the code to search through *some* of the text
boxes (with help from word.mvps.org!).
My problem is that some of the text box controls on the document seem
to be ignored by the code, and consequently the strings are not
replaced.
Has anybody encountered and/or (hopefully) solved this problem before?
Thanks in advance.
Leigh Hall
This is the code snippet that I am using for the main body search:
=====================================
With objWord.Selection.Range.Find
Do While .Execute(strFind, 0, , , , , 1, 1)
.Execute strFind, 0, , , , , 1, wdFindContinue, ,
strReplace, 1
DoEvents
iCnt = iCnt + 1
Loop
End With
=====================================
This is the code snippet that I took from mvps.org to search the text
boxes, etc:
=====================================
For Each styRange In objWordDoc.StoryRanges
Debug.Print styRange
With styRange.Find
.Text = strFind
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
iCnt = iCnt + 1
End With
Next styRange
======================================