Share via

Adding reference to macro template

Anonymous
2012-06-19T23:15:38+00:00

We have a macro-enabled template on our server that is being used as the base for a company form. I finally got everything working correctly with new documents created from the template (thanks Jay and Doug!) but we have a handful of old documents from before I got it working correctly that have old code embedded in them or are otherwise not linked to the template correctly.

I've been trying to figure out how to link an existing document to the macros in the template but I can't seem to figure it out nor find it on Google. If I open the template and the document together in the VB editor I can drag the template project onto the document project in the project explorer and the template is added to the references for the document. However, the macros don't run, and the reference disappears when the document is saved and closed.

If I go to Tools -> References and add the template document, it shows up in the project explorer, but I can't open the template ("project is unviewable") and again the macros don't work and the reference isn't saved with the document.

I'm stuck. Any tips? Thanks in advance.

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2012-06-20T01:26:00+00:00

We have a macro-enabled template on our server that is being used as the base for a company form. I finally got everything working correctly with new documents created from the template (thanks Jay and Doug!) but we have a handful of old documents from before I got it working correctly that have old code embedded in them or are otherwise not linked to the template correctly.

I've been trying to figure out how to link an existing document to the macros in the template but I can't seem to figure it out nor find it on Google. If I open the template and the document together in the VB editor I can drag the template project onto the document project in the project explorer and the template is added to the references for the document. However, the macros don't run, and the reference disappears when the document is saved and closed.

If I go to Tools -> References and add the template document, it shows up in the project explorer, but I can't open the template ("project is unviewable") and again the macros don't work and the reference isn't saved with the document.

I'm stuck. Any tips? Thanks in advance.

With the document open in Word (not the Visual Basic Editor), go to the Developer tab and then click on Document Template in the Templates section of the Ribbon and then click on the Attach... button and navigate to and select the desired template.  After doing that and clicking on OK, the macros in the template will be available for use in the document.

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Charles Kenyon 167.7K Reputation points Volunteer Moderator
2012-06-20T01:25:51+00:00

Open your existing documents and under the Developer Tab click on the Document Template button. Attach these documents to your new template. Make sure the checkbox to update Styles is not checked.

Note, this works with documents, not templates. If we are talking about old templates, write back for other suggestions.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful