Problem with Word 2016 macro

I cannot figure out why the attached macro for Word 2016 doesn't work…

When the “Style” dialog is open in Word 2016, the macro correctly clicks on the "Modify…" button. Yet after a few seconds, the notification centre displays a KM message saying that the macro couldn't find the button… And more important, the rest of the macro doesn't work, i.e. after the 0.5-sec pause, the shift-Tabs and the rest are not executed.

I'm stumped.

Any suggestions?



Sorry I can't directly address your issue since I don't have Word 2016.
But may I make a suggestion for an alternate solution?

Consider using Word VBA macros.

  • I have used Word (and Excel) for decades now, and have found the VBA powerful and easy to use.
  • You can get started by recording a Word VBA macro, and then tweaking it as needed.
  • There are tons of VBA macros and code snippets available on the Internet
  • The VBA editor/debugger is excellent

I have found that automation using the UI can be challenging, and is best left as a last resort. Any update to the OSX or App can break the UI automation.

Good luck, and let us know how it goes.

I don’t agree with you that VBA is “easy to use”. Its language is rather obscure and non-intuitive, and the user interface for the macro editor is positively atrocious. (I really don’t know how you can find it “excellent”.)

Documentation on the Internet is not often helpful. People make all kinds of assumptions about basic stuff that you should know but don’t because you’re just a casual script writer.

In addition, I’ve been burned in the past by Microsoft abandoning VBA and then restoring it two versions later. And there is also the very real risk of corruption of the Normal template (again, I’ve been burned), which can cause you to lose everything. I don’t particularly enjoy this form of abuse.

That said, in this particular case, it looks like your approach might work. I now have a macro that does just this:

ActiveDocument.Styles("Normal").LanguageID = wdFrenchCanadian
ActiveDocument.Styles("Normal").NoProofing = False

and it seems to be working. So thanks. But I still will rely on automation using a third-party tool like KM whenever I can. For me, VBA is only appropriate if I am desperate.

Perhaps so. Perhaps I've been using VBA so long it seems "natural" to me.
But my comment is really based on comparison with other scripting languages I have used.
Sorry to hear you've had such a bad experience with it.

I've been using VBA with MS Office Mac since 2011 without any issues.
Perhaps prior to that version MS was inconsistent.
VBA has consistently been a part of MS Office Windows for decades now.

I learned long ago to backup my VBA macros in all of the Office apps. You can easily export each VBA module to a text file with a ".bas" extension. And, of course, Time Machine will backup everything, including your Office Normal templates.

I'm glad you were able to find a solution.

VBA is just one more tool in my toolbox. I like to use the tool that is best for each job. A big advantage VBA has over KM for manipulating Word documents is that VBA has full access to all of the document objects, like paragraphs, styles, tables, etc.

On the other hand, KM is, in general, much easier to use.

Each of us have our favorite tools.

I don’t have a huge amount of scripting experience, but I did spend a lot of time in HyperCard back in the day. (I’ve never been able to get used to AppleScript either, though.)

I am sure you remember that Microsoft removed VBA functionality from Word 2008 altogether. It was a rather painful period. And then in Word 2016 they removed customizable toolbars and menus altogether. I can’t afford to spend my time customizing a tool that might not support my customization in the next upgrade. Hence my lack of desire to further explore VBA in particular.

But in this case the customization was pretty simple. (At least it looks like it.) So thanks again for the suggestion. And of course you’re right about backups and so on. But if corruption occurs and is not noticed right away (which can happen), the backup itself might end up with the corrupted version as well.

To be fair, I haven’t seen any real corruption in Word lately, so hopefully it’s a thing of the past. But I’ll never be able to trust Microsoft again in any case. The less I have to use its products, the happier I am.

Also, you might want to know that there ARE things that VBA cannot access. For example, as far as I can tell, there is no way to control the stupid “Don’t add space between paragraphs of the same style” option (in Paragraph) with VBA, at least in Word 2016. (I’ve tried. I might be wrong somewhere, but I cannot get it to work.) Thankfully, I have been able to use KM for this.

OK, the Press Button fails with error -25204 as reported in the Engine.log file, which is reported by to mean:

So basically Keyboard Maestro presses the button, but the action never completes, probably because Word is locking itself up performing the sub-dialog instead.

I suggest you simply disable reporting of the error and set the timeout to 1 second and that will resolve the problem.

Thanks, Peter. It does explain the failure. I am going to stick with VBA for this one for now, but I might need to take this into account for other macros in Word 2016 in the future.