# Solved: Open new WORD document from template with macros attached



## Ripperdan (Oct 28, 2009)

How do I open a new WORD document based on a template with macros so that those macros come over to the new document enabling the document to be moved to a different machine without the original template and still have the macros work.


----------



## Keebellah (Mar 27, 2008)

Well, how about mentioning the version of Word you are using?
If the template has macros and it's Word 2003 or earlier, the macro's come with it, if it's a Word 2007 or higher the template should first be a template with macro's and the location must be trsuted for the macro's to be active.
When a document is created based on a tamplae and the template is the file that contains the macro's, these will always come with it.
If the macro's are not in the template file but in the normal.dot(x) then thjat won't happen.
SSummarizing: the macro's must already be in the template file to be present in the doucument and of course the document in the case of 2007 and higher must saved with macro's

I hope I've been able to explain it in such a way that it makes sense for you.


----------



## Ripperdan (Oct 28, 2009)

My appologies. I should have know to include the version, which is OFFICE 2010.
I have a template named "Labeling Master.dotm" with several macros.
If I click "File", "New" and select the "Labeling Master.dotm" template, it makes a new document named "Document1" (or some other number). The macros don't come with it. Am I not making the new file correctly?
This procedure of opening the new file is done withing a macro and also when I do it manually. I have written my macro to first open the actual template and then save the template as a *docm. This works but seems kind of crude.
Our company recently upgraded from word 2002 to Office 2010.


----------



## Keebellah (Mar 27, 2008)

What I haven't tested here, bue the same as an Excel template with macros (xltm) when I create a new file via the template the macro's go along with it.
Are you sure that the macro's are in the template document and not that these haveen saved in the normat.dot?
You see, as with macro's in Excel, when you record a macro it will promt for a name and where this macro needs to be saved, default is the personal.xlsm in Excel and in Word it's generally the normal. dotm.
When you open the template in edit mode, and you open the vba project, where do you see the modules?


----------



## Ripperdan (Oct 28, 2009)

Yes, they are in the desired template, not the NORMAL.dot. The template in question is attached.

Under "Option", "Trust Center", I have the "Enable all macros" selected and "Trust access to the VBA project object model" checked. I have tried with those 2 items checked and not checked.


----------



## Keebellah (Mar 27, 2008)

Here is the result when saved as a word file (with macro's)
It just works, I think you must check that the file is saved *with macros*

Check the extension


----------



## Ripperdan (Oct 28, 2009)

I don't know what I am doing differently than you. When I make a new document based on the template and then look at the Project Explorer in the VBA window, the "TemplateProject(Labeling Master) has a Module1 with the macros there. There is no Module in the "Project(Document1) section. Maybe there is a setting that needs to be set up.


----------



## Keebellah (Mar 27, 2008)

Like I said, if you create a new document using the template as template (place it in the templates folder) you must not forget to save it as a document with macro's, if you don't do this it won't work, this is what I did, I didn't touch anything, I place the doc you sent me in my templats folder, created a new doc using this template, presseed the 8 and the 9 to see if it did anything, saved it a s doc with macros (doxm).

Closed everything, startend word, opened the saved doxm file and it works.
Check this, there is nothing wrong with the tempalte but I think you overlooked a step when saving


----------



## Ripperdan (Oct 28, 2009)

Your right I must be missing something because I still can't get it to work. I'll layout all the steps I do. Maybe you can see where my error is.
In advance, I really appreciate you taking so much time with me.
1. I click "File", "New" and "My Templates ICON"
2. Select the "Labeling MASTER.DOTm" template and click OK.
3. A new document is generated with a name of "Document1"
4. If I open the VBA Editor, I see the "TemplateProject(Labeling MASTER)" project with a Module1 and all the macros are present.
5. Also in the VBA Editor, I see the "Project(Document1)" project but there is no Module so therefore there no macros.
6. I then save "Document1" as "NEWDocument1.DOCm".
7. Checking back in the VBA Editor, I see the "Project(NEWDocument1)" project, but again, there is no Module in that project so therefore, no macros attached to it. The macros are still in the "TemplateProject(Labeling MASTER)" project.
8. If I move this "NEWDocument1.DOCm" to a different machine, the macros are not there.
Like I stated earlier, I sort of accomplished the task by opening the actual template (Instead making a new document based on the templae.) and then saving that template as "NEWDocument1.DOCm". The macros are then present in "NEWDocument1.DOCm" when I move it to another machine. It works but seems sort of crude.


----------



## Keebellah (Mar 27, 2008)

Sorry for my first answers, Í went deeper and see what you mean.
The Documents vba project contains a link' tot the template but not the actaul macro's, I misinterpreted this link as if it was the module with the macro's.
I checked all the save options but none show that you also copy the vba project into the new dcoument, so when the template is on a network share, everyone on the network that can access this share will have working macro's but if you mail the document it's over.
In a certain way this is the correct way of working, you create a document and no further alteratiosn must be allowed (macro wise), but I find this strange.
I think the Microsoft knowledgbase will heve to be consulted on the microsoft site or somebody else on the board that may have a solution for this.
Sorry but this is above my perception, if I find anything I'll post it.


----------



## Ripperdan (Oct 28, 2009)

Thanks again for all your help.


----------



## Lerst (Jul 15, 2010)

Thanks guys! these were very useful advises.


----------

