how to search delete more than one characters in a document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I use search & replace to delete a charachter in a document and it works fine.
I would like to delete several characters at the same time.
How can I do that??? Please HELP!!
 
I'm guessing from your question that these are non-contiguous characters?
That may be difficult. Would you describe what you are trying to delete
using S&R please and mention the version of Word please?
 
Terry Farrell said:
I'm guessing from your question that these are non-contiguous characters?
That may be difficult. Would you describe what you are trying to delete
using S&R please and mention the version of Word please?

--
Terry Farrell - MS Word MVP


these are the charachters i'm trying to delete: ß,Û,Þ etc.
I'm using word 2003.
 
Enter the characters in an array either by their ANSI number or as
characters (both shown below) then run the macro to remove them. If you need
to remove trailing space or punctuation then you'll need to add it between
the quotes.

Sub ReplaceList()
Dim vFindText As Variant
Dim i As Long

'vFindText = Array(Chr(223), Chr(219), Chr(222))
vFindText = Array("ß", "Û", "Þ")

With Selection
.HomeKey Unit:=wdStory
With .Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
Next i
End With
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Or, to not use Selection - generally not a good idea as Range is better - you
could use:

Sub Change()
Dim vFindText
Dim r As Range
Dim i As Long
vFindText = Array("f", "g", "d")
For i = 0 To UBound(vFindText)
Set r = ActiveDocument.Range
With r.Find
.Text = vFindText(i)
Do While .Execute(Forward:=True) = True
r.Delete
Loop
End With
Next
End Sub

Which deletes all the characters in the given array, in this case "f", "g",
and "d".
 
That's all very well, until you want to run the macro on only part of the
text, when the whole document range will not cut it ;)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top