Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-30-2023, 09:33 AM
hoosier122 hoosier122 is offline Help Creating a Simple Find & Replace with REGEX in Word Windows 10 Help Creating a Simple Find & Replace with REGEX in Word Office 2021
Novice
Help Creating a Simple Find & Replace with REGEX in Word
 
Join Date: May 2023
Posts: 3
hoosier122 is on a distinguished road
Default Help Creating a Simple Find & Replace with REGEX in Word

Greetings! I simply want to be able to use Regex within a VB script for Word.



Surely someone already has this script already written?

No, I don't want to use Word's built-in Find & Replace function including its "Wildcards" feature.

Code:
Sub LineCounter()
Dim regExp As Object
Set regExp = CreateObject("vbscript.regexp")

With regExp
    .Pattern = "(^p^p)"
    .Global = True
    Selection.Text = .Replace(Selection.Text, "^p")
End With
End Sub
The above code kind of works, but I don't want to have to highlight text AND this code also unpredictably breaks the formatting of Word documents in which it is run.

Help, please!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Creating a Simple Find & Replace with REGEX in Word Regex to find space after two-letter words at the of the line and replace Bachelar Word VBA 3 05-29-2022 07:03 AM
Help Creating a Simple Find & Replace with REGEX in Word Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed abdan Word VBA 3 01-18-2019 09:38 PM
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
Help Creating a Simple Find & Replace with REGEX in Word Convert RegEx to Word (Devanagari Font Find/Replace) gasyoun Word VBA 9 04-12-2013 04:15 PM
Help Creating a Simple Find & Replace with REGEX in Word Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:05 AM.


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