First off, I'm not very proficient at programming. I've got a few macros to help me with work, but I needed clear examples to make those.
I want to find any instances in a Word document that has multiple underscores and replace them with a set number of underscores. There could be anything from 30 to 5 underscores in a row, and I want to be able to find those and replace them with exactly 10 underscores. The underscores are most often in their own paragraph, but sometimes they're together with text.
I've had a look around on the site and online, but I can't see how to do it with an unknown number of underscores.
If someone could point me in the right direction, I'd be really grateful. Thanks.
All you need to do is to use wildcards!
This one line of code can do it:
ActiveDocument.Content.Find.Execute "_{5,30}", _
MatchWildcards:=True, Replace:=wdReplaceAll, _
ReplaceWith:="__________", Wrap:=wdFindContinue
Note:
The {5,30} part would leave underscores less than 5 or more than 30 untouched.
You can change it to {,30} to replace 30 underscores or less
Or {1,} to replace 1 or more underscores
Easy-to-follow article about wildcards can be found here.