Searching for spaces

J

Joanne

Hello, I wrote the following code to replace any instance of a semi colon and
one or more spaces following, but it doesn't seem to do anything. No errors,
just no result. Any ideas why this doesn't work?

Thanks very much for any help you can provide.

Sub GetSemis()
Set rng = ActiveDocument.Range
With rng.Find
.ClearFormatting
..Forward = True
.Wrap = wdFindContinue

.Text = (";& Chr(32){1,}")
With .Replacement
.ClearFormatting
.Text = "Hello"
End With
.Execute Replace:=wdReplaceAll
End With


End Sub
 
D

Dave Lett

Hi Joanne,

You have your search string wrong. It's actually looking for the ampersand,
a space, Chr(32). You also haven't specifically started a wildcard search.
Try the following instead:

With Selection.Find
.ClearFormatting
.Text = "; {1,}"
With .Replacement
.ClearFormatting
.Text = "Hello"
End With
.MatchWildcards = True
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

HTH,
Dave
 
J

Joanne

Thank you, it worked!

Dave Lett said:
Hi Joanne,

You have your search string wrong. It's actually looking for the ampersand,
a space, Chr(32). You also haven't specifically started a wildcard search.
Try the following instead:

With Selection.Find
.ClearFormatting
.Text = "; {1,}"
With .Replacement
.ClearFormatting
.Text = "Hello"
End With
.MatchWildcards = True
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

HTH,
Dave
 

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