Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

Word VBA to search and replace using wildcards

$
0
0

I would like to have a routine that will search (within "StartRange") for paragraph mark, any number, period, space, any capital letter and then replace that with paragraph mark, the original number, period, space, (Original), space, and the original capital letter.

Ex.:

^p
5. The...

would be replaced with

^p
5. (Original) The...

I started with the following (without limiting the wildcards to letters or numbers), but it does not find the matching patterns (I assume my syntax is off):

Dim StartRange As Word.Range
Set StartRange = Selection.Range
StartRange.Find.Execute FindText:="^p[*]. [*]", ReplaceWith:="^p[*]. (Original) [*]", Replace:=wdReplaceAll

I tried variations of the above - it does work with FindText:="^p5. T", ReplaceWith:="^p5. (Original) T", but not with any wildcard values I tried: *, #, 0-9, A-Z, etc., with and without brackets.  What is the proper syntax for using wildcards in this fashion?

Any help greatly appreciated!


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>