Use Word VBA to Replace Multiple Spaces in the Body and Footnotes
Question details
Replace consecutive spaces with a single space throughout a Word document, including footnotes and other document sections.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- An editor wants to automate a recurring document cleanup step before publication.
- Observed behavior
- Repeated ordinary spaces are reduced to one space in the document body and accessible story ranges, including footnotes, endnotes, headers, and footers.
Open the document in desktop Microsoft Word and make sure you can access the VBA editor. The macro below replaces ordinary spaces only; it does not change tabs or nonbreaking spaces.
Run a VBA macro across Word story ranges
Use this approach to clean repeated ordinary spaces in the body and other accessible document stories in one run.
Word stores the body, footnotes, endnotes, and headers and footers in separate story ranges. The macro follows each story range and its linked ranges, using wildcard Find and Replace without wrapping beyond the current range.
In desktop Word, open the document, then choose Developer > Visual Basic. On Windows, you can also press Alt+F11.
In the VBA editor, choose Insert > Module and paste this code: Sub ReplaceRepeatedSpaces() Dim story As Range Dim rng As Range For Each story In ActiveDocument.StoryRanges Set rng = story Do While Not rng Is Nothing With rng.Find .ClearFormatting .Replacement.ClearFormatting .Text = " {2,}" .Replacement.Text = " " .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute Replace:=wdReplaceAll End With Set rng = rng.NextStoryRange Loop Next story End Sub
Place the cursor inside ReplaceRepeatedSpaces and choose Run > Run Sub/UserForm. Return to the document and check the body, footnotes, and relevant headers and footers.

Replace repeated spaces manually in a Word story
Use Word's wildcard Replace when you need to clean a section without running a macro.
Edit Word Documents with WPS Writer
WPS Office is a free, lightweight Office alternative with a familiar interface and compatibility with Word formats for a smoother move between applications. Use WPS Writer to review and edit documents; it does not run the Word-specific VBA solution described above as a guaranteed substitute.

Frequently Asked Questions
Will the macro also clean footnotes and endnotes?
Yes, it processes accessible footnote and endnote story ranges returned by ActiveDocument.StoryRanges, along with their linked ranges.
Does the macro replace tabs or nonbreaking spaces?
No. The Find pattern contains an ordinary space, so it only reduces runs of ordinary spaces. Tabs and nonbreaking spaces require separate handling.
Why use wdFindStop instead of wdFindContinue?
wdFindStop keeps each Find and Replace operation within the current range. The macro then advances to the next linked story range with NextStoryRange.
Can I run this macro in Word for the web?
No. Open the document in desktop Microsoft Word and use Developer > Visual Basic to insert and run the VBA macro.




