Word Macro for Sentence Spacing After Punctuation and Abbreviations
Question details
Create a Word macro that adds sentence spacing while accounting for quotation marks and common abbreviations.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A user wants to apply consistent spacing after sentence-ending punctuation without treating listed abbreviations as sentence endings.
- Observed behavior
- The desired result is two spaces after sentence punctuation, including punctuation followed by a closing quotation mark, while listed abbreviations are left unchanged.
Test the macro on a short sample containing sentences, closing quotation marks, and the abbreviations you use. Make sure Word allows you to access the VBA editor and run macros under your organization's security settings.
Run a Word VBA macro that skips listed abbreviations
Use this macro to change existing spaces after likely sentence endings to two spaces in the main document body.
The macro works backward through the main document body, checks for closing quotation marks, and skips periods belonging to a delimiter-separated list of abbreviations. It only adjusts existing ordinary spaces; it does not insert spaces where none exist or process headers, footers, or text boxes.
The abbreviation list is a practical exception list, not a complete sentence detector. A listed abbreviation at the end of a sentence will also be skipped, while an unlisted abbreviation may be mistaken for a sentence ending.
In Word, open the document and select Developer > Visual Basic, or press Alt+F11 where supported. In the editor, select Insert > Module.
Paste this code into the module: Option Explicit Sub AddSentenceSpacing() Dim doc As Document Dim i As Long, j As Long, spaceStart As Long Dim ch As String, nextCh As String Set doc = ActiveDocument For i = doc.Content.End - 2 To doc.Content.Start Step -1 ch = doc.Range(i, i + 1).Text If ch = "." Or ch = "!" Or ch = "?" Then If ch <> "." Or Not IsListedAbbreviation(doc, i) Then j = i + 1 Do While j < doc.Content.End - 1 nextCh = doc.Range(j, j + 1).Text If nextCh = Chr(34) Or nextCh = Chr(39) Or _ nextCh = ChrW(8221) Or nextCh = ChrW(8217) Then j = j + 1 Else Exit Do End If Loop spaceStart = j Do While j < doc.Content.End - 1 If doc.Range(j, j + 1).Text <> " " Then Exit Do j = j + 1 Loop If j > spaceStart And j < doc.Content.End - 1 Then nextCh = doc.Range(j, j + 1).Text If nextCh <> vbCr And nextCh <> vbLf And _ nextCh <> vbTab And nextCh <> Chr(7) And _ nextCh <> Chr(11) Then doc.Range(spaceStart, j).Text = " " End If End If End If End If Next i End Sub Private Function IsListedAbbreviation(doc As Document, dotPos As Long) As Boolean Dim items As Variant, item As Variant Dim startPos As Long, previousChar As String items = Split("Mr.|Mrs.|Ret.|Hon.|R.S.V.P.|Lt. Col.", "|") For Each item In items startPos = dotPos + 1 - Len(CStr(item)) If startPos >= doc.Content.Start Then If StrComp(doc.Range(startPos, dotPos + 1).Text, CStr(item), vbTextCompare) = 0 Then If startPos = doc.Content.Start Then IsListedAbbreviation = True Exit Function End If previousChar = LCase$(doc.Range(startPos - 1, startPos).Text) If InStr(1, "abcdefghijklmnopqrstuvwxyz0123456789", previousChar, vbBinaryCompare) = 0 Then IsListedAbbreviation = True Exit Function End If End If End If Next item End Function
In the Split line, add other abbreviations separated by the | character. Include each abbreviation's final period, and keep the full form for multiword entries such as Lt. Col.
Return to Word, select Developer > Macros, choose AddSentenceSpacing, and select Run. Review the sample for false matches before using the macro on a full document.

Edit Word Documents with WPS Writer
WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing Word documents. Its format compatibility helps you move existing files into WPS Writer, although it does not fix or replace Microsoft Word's VBA macro behavior.

Frequently Asked Questions
How do I add more abbreviations to the macro?
Open the VBA module and edit the string in the Split line. Add each abbreviation with its final period, using | between entries, such as Dr.|Prof.
Does the macro add spaces after a closing quotation mark?
Yes. It checks for straight and curly closing quotation marks after punctuation, then changes an existing run of ordinary spaces to two spaces.
Why did the macro skip an abbreviation at the end of a sentence?
The macro skips every period that ends a listed abbreviation, even when that abbreviation also ends a sentence. Review those cases manually or adapt the detection logic for your documents.
Will the macro process headers and footers?
No. It uses ActiveDocument.Content, which covers the main document body. Headers, footers, and text boxes require separate story-range processing.
Can I use Word wildcards to preserve an abbreviation during replacement?
Yes. In a wildcard search, capture the abbreviation in parentheses and keep the following spaces outside the capture group. Use \1 in the replacement to retain the captured abbreviation, followed by the spacing you need. Test individual matches before choosing Replace All.




