A
Adsoftware
I am using VBA within Word 2002 to try and automatically
replace text in a header. I've tried the storyrange
approach and the looping thru the headers collection but I
CAN'T get the Replace function to work.
When I step through the code, the Find.Found property
returns false, indicating it's not finding my text at
all. HELP.
I'm attaching the generic function I use to do this...
Sub ReplaceHeadersFooters(sFind As String, sReplace As
String)
Dim MySelection As Variant
Dim vntStories As Variant
Dim x As Long
With ActiveDocument
For x = 0 To .StoryRanges.Count - 1
Set MySelection = ActiveDocument.StoryRanges(1)
With MySelection.Find
'With .StoryRanges(1).Find
.Text = sFind
.Replacement.Text = sReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next x
End With
End Sub
replace text in a header. I've tried the storyrange
approach and the looping thru the headers collection but I
CAN'T get the Replace function to work.
When I step through the code, the Find.Found property
returns false, indicating it's not finding my text at
all. HELP.
I'm attaching the generic function I use to do this...
Sub ReplaceHeadersFooters(sFind As String, sReplace As
String)
Dim MySelection As Variant
Dim vntStories As Variant
Dim x As Long
With ActiveDocument
For x = 0 To .StoryRanges.Count - 1
Set MySelection = ActiveDocument.StoryRanges(1)
With MySelection.Find
'With .StoryRanges(1).Find
.Text = sFind
.Replacement.Text = sReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next x
End With
End Sub