dwe0608
asked on
VB6 and MsWord
Hi Guys,
Trying to use the find and replace function from VB6 with MSWord - coding as follows:
The code works fine for words in the text body but doesn't recognise any of the words which match the string to find in either a header or a footer.
Can someone enlighten me on why this would be the case?
MTIA
DWE
Trying to use the find and replace function from VB6 with MSWord - coding as follows:
'On Error Resume Next
With wb.Document.Application.Selection.Find
.ClearFormatting
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Text = strFind
With .Replacement
.ClearFormatting
.Text = sReplace
End With
If iMode = SingleReplace Then
.Execute Replace:=Word.WdReplace.wdReplaceOne
Else
.Execute Replace:=Word.WdReplace.wdReplaceAll
End If
End With
The code works fine for words in the text body but doesn't recognise any of the words which match the string to find in either a header or a footer.
Can someone enlighten me on why this would be the case?
MTIA
DWE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks for the assistance - that solved the problem.
Regards
DWE
Regards
DWE
Note that simply stepping through the StoryRanges collection only returns the the range of the first instance of each story type. This might have worked with your current document, but it could miss out parts of a more complex document. If you encounter this in future, bear in mind the code in my comment above.
ASKER
Hi GrahamSkan, at the time of accepting the answer, your answer was not visible - I dont know how that happened ... had I seen your answer I probably would have accepted it .... the implementation I utlised is not too dissimilar to what you have posted.
Many thanks for the input ....
DWE
Many thanks for the input ....
DWE
That's good news. Thanks for letting us know.
Open in new window