Hi, folks. Could you please share VBA code that would search
an open Word doc file entirely, and remove all instances of a
specified text, except the very first instance?
For example, if my open doc file had 4 instances of the text
"supplies", then the desired VBA code would remove/delete
the last 3 places where "supplies" appeared, but keep the first
instance of it, as is, where it is.
Is this even possible?
Thank you for your help.
Wayne
Helmut Weber - 20 Aug 2006 05:20 GMT
Hi Wayne,
like this:
Sub Test0136784()
Dim rngDcm As Range
Set rngDcm = ActiveDocument.Range
With rngDcm.Find
.Text = "fox"
If .Execute Then
rngDcm.Collapse Direction:=wdCollapseEnd
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End If
End With
End Sub

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
WayneK - 20 Aug 2006 10:50 GMT
Helmut, this is fantastic code. Thank you so very much
for helping me.
Have a beautiful day.
Wayne