View Single Post
 
Old 02-24-2023, 03:18 AM
alex100 alex100 is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Use RegEx and preserve the original text formatting

The script below uses RegEx to find and replace within a Word selection. The problem is that many times, depending how the text is formatted, it changes this formatting style.

How can I search and replace (using RegEx) while keeping everything else intact?

Thank you!

Alex

Code:
Dim RegEx As Object
Set RegEx = CreateObject("vbscript.RegExp")
With RegEx
    .pattern = "old_text"
    .Global = True
    Selection.Text = .replace(Selection.Text, "new_text")
End With
Reply With Quote