M
Marceepoo
In the macro below, I'm trying to tell Word VBA (Word 2003 running in Xp) to
do a search and replace while the search text is true.
Alas, I can't get Word to see that the condition is true, i.e., that the
search text is in the document.
Obviously I'm doing something wrong. But I can't figure out what it is, or
where to find info about how to fix it.
any help would be much appreciated.
Thanks,
marceepoo
Sub RemovSmithDeliveryReportTest()
'
' mbh February 10, 2008
'
'---------------------------------------
Dim sTemp As String
Dim sDoWhileSearchConditn As String
sDoWhileSearchConditn = "findText:='Smith Delivery Summary Report for',
Forward:=True, " _
& "MatchWildcards:=True, MatchCase:=false, Wrap:=wdFindStop)"
sDoWhileSearchConditn = Replace(sDoWhileSearchConditn, "'", Chr(34))
sTemp = sDoWhileSearchConditn
sTemp = sDoWhileSearchConditn
Selection.HomeKey wdStory
' Selection.Find '.ClearFormatting
With Selection.Find
'
Do While .Execute(sDoWhileSearchConditn) = True
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Smith Delivery Summary Report for"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Smith and their affiliates."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
'Insert line separating the Smith documents
Selection.TypeParagraph
Selection.TypeText Text:= _
"____________________________________________________________"
Selection.TypeText Text:="_______________"
Selection.TypeParagraph
Selection.TypeParagraph
Loop
End With
End Sub
do a search and replace while the search text is true.
Alas, I can't get Word to see that the condition is true, i.e., that the
search text is in the document.
Obviously I'm doing something wrong. But I can't figure out what it is, or
where to find info about how to fix it.
any help would be much appreciated.
Thanks,
marceepoo
Sub RemovSmithDeliveryReportTest()
'
' mbh February 10, 2008
'
'---------------------------------------
Dim sTemp As String
Dim sDoWhileSearchConditn As String
sDoWhileSearchConditn = "findText:='Smith Delivery Summary Report for',
Forward:=True, " _
& "MatchWildcards:=True, MatchCase:=false, Wrap:=wdFindStop)"
sDoWhileSearchConditn = Replace(sDoWhileSearchConditn, "'", Chr(34))
sTemp = sDoWhileSearchConditn
sTemp = sDoWhileSearchConditn
Selection.HomeKey wdStory
' Selection.Find '.ClearFormatting
With Selection.Find
'
Do While .Execute(sDoWhileSearchConditn) = True
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Smith Delivery Summary Report for"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Smith and their affiliates."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
'Insert line separating the Smith documents
Selection.TypeParagraph
Selection.TypeText Text:= _
"____________________________________________________________"
Selection.TypeText Text:="_______________"
Selection.TypeParagraph
Selection.TypeParagraph
Loop
End With
End Sub