Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-24-2023, 03:18 AM
alex100 alex100 is offline Use RegEx and preserve the original text formatting Windows 7 64bit Use RegEx and preserve the original text formatting Office 2016
Advanced Beginner
Use RegEx and preserve the original text formatting
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Use RegEx and preserve the original text formatting Formatting figures ?? - Preserve formatting of shapes for future use ksor Word 4 11-04-2019 11:35 AM
Use RegEx and preserve the original text formatting Is it spossible to preserve the original line numbers for reference when editing a document? mr_gray Word 3 10-02-2015 05:53 AM
Use RegEx and preserve the original text formatting Need macro to merge files in Word and preserve formatting Carolin Word VBA 3 12-14-2014 04:01 AM
How to extract text from a cell and preserve special formatting? epid011 Word VBA 2 04-04-2014 04:54 PM
Use RegEx and preserve the original text formatting Cut and paste a range of cells and preserve formatting StarWeaver Excel 1 03-02-2010 01:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft