adderslj: (Default)
[personal profile] adderslj
I 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.

Date: 2004-03-03 02:21 pm (UTC)
From: [identity profile] slog.livejournal.com
dood, change the document setup settings and change it to single spacing.

Date: 2004-03-03 08:58 pm (UTC)
From: [identity profile] ashamel.livejournal.com
The great thing about Word is that you can just record what you're doing as a macro. For example, this is me replacing all instances of 2 spaces in a document with 1 space. Then you just asign it to a key combo (like Ctrl-Shift S), and you're right:

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

June 2013

S M T W T F S
      1
2345678
910 1112131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 12th, 2026 07:59 am
Powered by Dreamwidth Studios