E
Ed
I have a text "banner" that repeats throughout my document. I do a
Find/Replace to delete this banner (replace it with "") using the code
below, which works fine - except it won't Find/Replace the banner at the
very end of the document. The document is text-only, with each line ending
in a paragraph mark. The string being searched for consists of three
lines/paragraphs. It is the first three paragraphs of the doc. At the end
of the document, this would also include the very last paragraph mark in the
doc.
If there is a better way to accomplish this, I would appreciate any help.
Ed
Set doc1 = Documents.Open(FileName:=strFldr & "\" & strDump)
Set rngDoc = doc1.Range
' Check for banner
Set rngTIR = doc1.Paragraphs(1).Range
rngTIR.SetRange _
Start:=doc1.Paragraphs(1).Range.Start, _
End:=doc1.Paragraphs(3).Range.End
If rngTIR.Words(4).Text = "HERE" Then
strUncl = rngTIR.Text
End If
' If header exists, delete it everywhere
If strUncl <> "" Then
Debug.Print strUncl
Set rngTIR = rngDoc
rngTIR.Find.Execute _
FindText:=strUncl, _
ReplaceWith:="", _
Replace:=wdReplaceAll
End If
Find/Replace to delete this banner (replace it with "") using the code
below, which works fine - except it won't Find/Replace the banner at the
very end of the document. The document is text-only, with each line ending
in a paragraph mark. The string being searched for consists of three
lines/paragraphs. It is the first three paragraphs of the doc. At the end
of the document, this would also include the very last paragraph mark in the
doc.
If there is a better way to accomplish this, I would appreciate any help.
Ed
Set doc1 = Documents.Open(FileName:=strFldr & "\" & strDump)
Set rngDoc = doc1.Range
' Check for banner
Set rngTIR = doc1.Paragraphs(1).Range
rngTIR.SetRange _
Start:=doc1.Paragraphs(1).Range.Start, _
End:=doc1.Paragraphs(3).Range.End
If rngTIR.Words(4).Text = "HERE" Then
strUncl = rngTIR.Text
End If
' If header exists, delete it everywhere
If strUncl <> "" Then
Debug.Print strUncl
Set rngTIR = rngDoc
rngTIR.Find.Execute _
FindText:=strUncl, _
ReplaceWith:="", _
Replace:=wdReplaceAll
End If