View Single Post
 
Old 06-01-2023, 05:50 AM
hoosier122 hoosier122 is offline Windows 10 Office 2021
Novice
 
Join Date: May 2023
Posts: 3
hoosier122 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Your code is working on Selection.Text which is why it expects you to SELECT the text first. If you don't want to first select the text then you need to ask it to work on a range eg
ActiveDocument.Range.Text

Also, you are telling the code to replace the Text (which is an unformatted string of text) with another unformatted string of text - this is why your code is removing the formatting.

Some examples of others use of Regex in VBA might give you some hints to fix your code
Include All Stories in VBA RegEx Search in MS Word - Stack Overflow
microsoft word - Use RegEx and wildcard search to find a pattern - Super User
Using VBScript Regex in Word VBA

Are you really using vbscript or are you using VBA? It appears to be VBA in your example.
Thank you so very much. I'll digest those examples later.

I'm using whatever language is in the Word menus when you click 'Visual Basic.' It says Visual Basic for Applications ... so I guess VBA?

Sorry, I know C++ and PHP, but never took the time to learn Basic, so I just try to piece it together when I need to work in VB. And of course I get the help of this forum!

Thanks again.
Reply With Quote