A family of Microsoft word processing software products for creating web, email, and print documents.
Thanks for posting. See if the following works for you. I asked Copilot:
"Word" VBA regex find space followed by uppercase character and add return between space and character
and it gave my the following VBA:
Sub AddReturnBetweenSpaceAndUppercase()
Dim regEx As Object
Dim matches As Object
Dim match As Object
Dim docRange As Range
' Create RegExp object
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = " ([A-Z])" ' Space followed by uppercase letter
regEx.Global = True
regEx.IgnoreCase = False ' Case-sensitive (only uppercase)
' Work on the whole document
Set docRange = ActiveDocument.Content
' Run regex replace: replace space+uppercase with paragraph mark + uppercase
docRange.Text = regEx.Replace(docRange.Text, vbCr & "\1")
MsgBox "Done! Paragraph breaks inserted.", vbInformation
End Sub
Here are the notes accompanying the code:
How It Works
Pattern:
-
" ([A-Z])"→ matches a space followed by an uppercase letter (A–Z).- The uppercase letter is captured in group 1
([A-Z]).
- `vbCr & "\1"` → inserts a paragraph break (`vbCr`) before the captured uppercase letter. **Scope**: - `ActiveDocument.Content` → applies to the entire document. - The uppercase letter is captured in group 1
Important Notes
- This replaces all matches in the document at once.
- If you want to preserve formatting, you should use Word’s
Findwith wildcards instead of replacing.Textdirectly (because.Textreplacement removes formatting).
Formatting-Safe Alternative (Word Wildcards)
Vba
Sub AddReturnFormattingSafe()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = " ([A-Z])"
.Replacement.Text = "^p\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
MsgBox "Done! Paragraph breaks inserted.", vbInformation
End Sub
Explanation:
-
" ([A-Z])"with wildcards matches space + uppercase. -
^p\1inserts a paragraph break before the uppercase letter. - This method keeps formatting intact.