Is this Find/Replace possible to do by VBA?

  • Thread starter Southern at Heart
  • Start date
S

Southern at Heart

I am needing to do an advanced search and replace on large amounts of text.
I need to search for <ele>, and then </ele> and delete both of these and
everything in between. The problem is that this this phrase is found many
times in the document and I need to delete all of them.
Many thanks for any help
Southern At Heart
 
H

Helmut Weber

Hi Southern at Heart,

like that:

Sub Test400A()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "\<ele>*\</ele\>"
.Replacement.Text = ""
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub

You might need to delete possible remaining
double spaces in addition.



--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
F

fumei via OfficeKB.com

You do not need VBA to do this. Find and Replace will do it.

Find: \<ele\>*\<\/ele\>

Replace: leave blank

Click Replace All.

All text between <ele> and </ele> - including the <ele> and the </ele> - will
be replaced with nothing.

Note: you must have Use wildcards checked on the Find/Replace dialog.
 

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