HappyNanaMO
HappyNanaMO

Reputation: 353

Word Save Template command returning error

I recently discovered the blissful convenience of being able to use the File, Save command from within the VBA Editor window to save the currently attached template without having to actually be in the template or close out of Word.

I thought it would be nice to have this command available on a Ribbon Tab or the QAT or even a keyboard shortcut, so I first added the Save Template command to a Ribbon Tab. But when I clicked on the tab, nothing happened.

I thought perhaps I needed to tweak things a bit with a macro, so I recorded a macro and clicked on the command, to see what the VBA statement would look like. It looks simple and straightforward enough, very similar to a bazillion other "ActiveDocument" macros I have stored that run without any issues:

    ActiveDocument.AttachedTemplate.Document.Save

But when I run the macro, I get the standard "Runtime error" message, with no hint as to what is wrong.

I cannot find any documentation regarding this command in any of my source material or anywhere on Google, nor can I find any discussions about it.

Any ideas what's missing here? Thanks in advance!

Upvotes: 2

Views: 73

Answers (1)

Doug Glancy
Doug Glancy

Reputation: 27478

As I discovered, and Cindy Meister confirmed, the following works:

ActiveDocument.AttachedTemplate.Save

It will work even if the template is closed. The version that you got from the Macro Recorder, ActiveDocument.AttachedTemplate.Document.Save works only if the template is open. The version above works whether it's open or not. I don't program much in Word, but it looks like a template's Document object/property is instantiated when the template is opened and otherwise is nothing.

Upvotes: 1

Related Questions