Search for a string in a WORD document and execute macro?


More specifically, I have a novel in WORD that has superfluous hyphens. I want to search for all instances of the hyphen, delete it, and massage the area around the hyphen with a macro (way too many to do by hand–over 2000). Is there a way KM can do this?

It’s easy enough to write a macro that deletes the hyphen, but clearly, I want the search to move the cursor to the first hyphen, execute a macro, then go on to all the remaining instances of hyphens in the doc.

Search and Replace in WORD allows you to search and delete, but I need to do further corrections to each area as well.


Hey @landmark,

Tell us what version of Word you’re using.

Be more specific about the massaging you want to do – and provide exact examples if possible.

It would be best if you could provide a big enough sample for people to experiment with in Word.

Do you have custom formatting? If not can you export to plain-text?

What you’re wanting to do is (probably) complex but may be possible by scripting Word.

Brute-forcing the UI? Maybe…


Thanks, Chris.
I’ll probably just do it another way.
I am surprised that a searching for a string and having it trigger a macro seems to be so complicated.
Is this inherently a difficult problem with a program like KM, or is there hope that Peter can implement such a function?

That's because you're doing the job in Word.

And it might not be so very complex to script in VB (or otherwise), but we can't help you if you don't give us the tools to do so.

You're asking for a magic spell and not providing exact specifications.


Since this is all in Word, I would use Word VBA. You can get a good start by recording a Word Macro, using the manual steps you want to automate.

If you get stuck with this, then if you can share an example Word doc with me, and provide the detailed steps to automate, I'll try to help.