Macro That Deletes Certain Words in a Microsoft Word Document

I created a macro that deletes certain words in a Word document.

After I finished building it, I hit the "run" button and it worked. Now, when I hit the macro command button, the macro does not work.

I'm sure I've done something wrong.

Delete Adverbs.kmmacros (58 KB)

Macro-Image

Howdy, if possible post the macro itself so we can take a look at it and see what might be going wrong. As one of the moderators likes to say, "If we're not testing we're guessing, and guessing often wastes people's valuable time". :laughing: If you need help on how to post the macro, just let us know and we can walk you through it.

If you haven’t had the opportunity to read this tutorial, I highly recommend it. It will help you get the most help for your question.

Tip: How Do I Get The Best Answer in the Shortest Time?

-Chris

Hey @LM_C,

You're going about this the hard way.

Use an Execute an AppleScript action to run the following code:

tell application "Microsoft Word"
   set myFind to find object of text object of front document
   tell myFind
      execute find find text "Now^w" replace with "" replace replace all
      execute find find text "the^w" replace with "" replace replace all
   end tell
end tell

Adjust as necessary.

“^w” means whitespace.

-Chris

1 Like

I can't use Keyboard Maestro to do it?

You definitely can. One way is by placing this AppleScript into the macro itself.

Are there other ways of doing it without using AppleScript, and using just KM native actions? No doubt, but sometimes AppleScript, or a shell script, or some JavaScript are much more efficient and reliable.

-Chris

Why do I need to add "w"?

I copy and pasted the script. I know I did something wrong, but I don't what.

I don't understand.

It's not a “w” it's “^w”, and I said what it meant in my post above.

Run the script from Apple's Script Editor.app, and see if it works...

-Chris