0
votes

I was wondering if it's possible to fire Word commands via vba macros? What I'm essentually trying to do is to make it easier for users to open the New document or template window that you can find via New --> Document --> My templates

I see that I can add a custom tab, alteast in Word 2010. But I've already got a custom tab I've added using Custom UI Editor for Microsoft Office. But it doesn't show up when trying to customize the Ribbon. I also tried to record a macro and just open the window where you choose which template you want to open. But it didn't record the action that makes the window actually appear.

Any ideas?

1
Please see [my answer to a similar question][1]. [1]: stackoverflow.com/questions/5008123/…domke consulting

1 Answers

1
votes

Yes this is possible, although the Backstage view in Word 2010 makes this a little tricky. Basically, Word comes with many built-in macros that control its commands and that are accessible via VBA. These commands can be found by displaying the Developer Tab, clicking the Macros button, and changing the Macros in: menu of the Macros dialog box to display Word commands:

enter image description here

To access the My templates dialog box via VBA, use this code:

Application.Run MacroName:="FileNewDialog"
SendKeys "%NM"

FileNewDialog accesses the existing Word macro for displaying Backstage view and Sendkeys uses the Alt-key keystrokes to maneuver and open the My templates dialog box (see the Word 2010 VBA help entry for more on SendKeys). Place the code into a Sub and create a QAT or Ribbon button to execute and you should be good to go.

Important note about testing SendKeys: SendKeys cannot be tested by stepping through the code in the VBA IDE as the keystrokes it sends out when running are sent to the active window at the time of execution (which would be the VBA development window). To test SendKeys, save the macro and attach it to a QAT button, which can be depressed, as needed, for testing.