Double space after period, except when...

J

JayneBartram

Hi, I've been using this really helpful macro offered by Allen Wyatt
on his "Word tips" web page.

Sub TwoSpaces()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([.\?\!]) {1,}"
.Replacement.Text = "\1 "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

It replaces any number of spaces after a period with 2 spaces, as
required by my UK organisation.
What it doesn't do is add 2 spaces after a period if there is
currently no space after said period.

This punctuation error occurs often here, so please can anyone tell me
how the above macro can be modified to take care of this extra
problem, if possible?

Regards,
Jayne Bartram
 
D

Doug Robbins - Word MVP

Replacing this line of the code

..Text = "([.\?\!]) {1,}"

with

..Text = "([.\?\!])"

would cause two spaces to be inserted after any . ? or !

That code should be run first, so that if there are already spaces there,
running the second code will reduce the number of them to two.

BUT, if there are decimal numbers in your document you would end up with two
spaces after the decimal point. To fix that, you would then need to use

". ([0-9]{1,})"

and replace with

".\1"

to remove those two spaces. Note there are two spaces between the . and the
( above.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

JayneBartram

Replacing this line of the code

.Text = "([.\?\!]) {1,}"

with

.Text = "([.\?\!])"

would cause two spaces to be inserted after any . ? or !

That code should be run first, so that if there are already spaces there,
running the second code will reduce the number of them to two.

BUT, if there are decimal numbers in your document you would end up with two
spaces after the decimal point. To fix that, you would then need to use

". ([0-9]{1,})"

and replace with

".\1"

to remove those two spaces. Note there are two spaces between the . and the
( above.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Thanks so much, that's a big help. I 'll have a go at including your
suggested code.

Regards,
Jayne Bartram
 

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