Home > Mobile >  VBA Word - Find a portion of a word, extend the selection and replace new selection with a new word
VBA Word - Find a portion of a word, extend the selection and replace new selection with a new word

Time:12-14

I want to write a sub routine to find all occurrences of a substring, then extend the selection with specified number of characters and replace this new text in all of document body at once. Is it possible?

doc.Range.Find.Execute findtext:="T04-WPA-"
Selection.MoveRight Unit:=wdCharacter, Count:=6, Extend:=wdExtend
'(Replacing procedure)     

CodePudding user response:

You don't even need VBA for this! All you need is a wildcard Find/Replace where:

Find = T04-WPA-??????
Replace = new string

even an ordinary Find/Replace where:

Find = T04-WPA-^?^?^?^?^?^?
Replace = new string
  • Related