how to search delete more than one characters in a document

R

Rudy

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!!
 
T

Terry Farrell

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?
 
R

Rudy

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.
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Rudy

I did not suspect that I would get such good results and so fast. Thank you
very much.
 
G

Graham Mayor

You are welcome :)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

fumei via OfficeKB.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".
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top