Twice The Space, Half The Pleasure
Mar. 3rd, 2004 11:24 amI really must figure out scripting in Word at some point, so I can write myself a macro to strip double spaces from a document. I figure it'll save me 15 minutes a week in Find/Repacing contributors' copy.
no subject
Date: 2004-03-03 02:21 pm (UTC)no subject
Date: 2004-03-03 08:58 pm (UTC)Sub Spaces2()
'
' Spaces2 Macro
' Macro recorded 4/03/2004 by David Carroll
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
It probably needs some fiddling with to make sure it does what you want. For example, it seems to affect everything even if you only have a subsample selected. If you want more specific rules, you need to look at wildcards. For example, this will replace any number of spaces with a single space, but only if following a sentence terminator (. ? !):
Sub Spaces2a()
'
' Spaces2a Macro
' Macro recorded 4/03/2004 by David Carroll
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([.\!\?]) {2,}"
.Replacement.Text = "\1 "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub