Find and Replace all words that have a certain value in them, not just the value itself.

  • Thread starter Thread starter =?iso-8859-1?q?El_Capit=E1n_de_las_Albondigas?=
  • Start date Start date
?

=?iso-8859-1?q?El_Capit=E1n_de_las_Albondigas?=

I want to be able to do a find/replace on all words that have "moogoo"
as part of the word. For example, if it finds "Franklinmoogoo" I want
it to replace the entire word with nothing. Currently I can only
replace moogoo with nothing, leaving me with Franklin, which I don't
want. I've tried using the wild card and finding "*moogoo" but for
some reason that finds the entire string of characters, including
spaces, before "moogoo." So, if my sentence said, "Hi my name is
Franklinmoogoo." It would highlight the entire sentence to replace.
I just want Word to highlight Franklinmoogoo and replace that. Any
ideas?

Gracias,
Sean
 
It is probably possible with Find and Replace and I can almost get
there except for a few cases. Klaue Linke or Graham Mayor may be by
to school us both. In the meantime, I believe you could do it like
this using a macro:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "moogoo" 'find the text string
While .Execute
'with found string, move the range forward while any alphabetical
character is encountered.
oRng.MoveEndWhile
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
'with the found string, move the range backwards while any
alphabetical character is encountered.
'500 is just an arbitrary value large enough for probably all
cases
oRng.MoveStartWhile
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", -500
'Delete the range
oRng.Delete
Wend
End With
End Sub
 
Back
Top