Group:  Microsoft Word ยป microsoft.public.word.vba.beginners
Thread: template change

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

template change
"DualStar" <jallin[ at ]dualstar.ca> 01.02.2006 21:07:58
I created a new template based on an old template (same file name). I
have renamed the command buttons so the code is easier to read (in the
old template they were left at default CommandButton1, etc.)and added
in some other functionality. Now I have a fully functional template for
any future documents based on this template and it works fine. I didn't
realize when you open a document based on a template none of the coding
goes with it. Now when someone opens an old document that they have
saved on their computer none of the command buttons work because (I
think) it references the new template. Is there anyway to fix this? I
have tried to open the old document and change the code for the command
buttons in the referenced template file but that doesn't work. I have
also tried to cut and paste the code into ThisDocument of the old
document for a quick fix but that doesn't work either. Any help would
be greatly appreciated. Thank you in advance.

RE: template change
Chuck Henrich 02.02.2006 12:29:04
You say that you named the new template the same name as the old template.
Did you store the new template in the same folder as the old one - ie did you
overwrite the old with the new? If so then the document should open with the
new template attached. If your new template is in a different folder then it
should have a different name to avoid potential confusion, for both yourself
and Word.

In any case you can use an AutoOpen macro to detect what template is
attached to a particular document, and attach a different one if it matches
criteria, eg:

Sub AutoOpen()

Dim strOldTemplate As String
Dim strNewTemplate As String

strOldTemplate = "YourOldTemplate.dot"
strNewTemplate = "c:\YourNewTemplate.dot"
'include the path in strNewTemplate
'if it is not a global template

If ActiveDocument.AttachedTemplate = _
strOldTemplate Then
ActiveDocument.AttachedTemplate = _
strNewTemplate
End If

End Sub

Store the AutoOpen macro in your Normal.dot. Bear in mind the following
(taken from the VBA help file):

"Just like other macros, auto macros can be stored in the Normal template,
another template, or a document. In order for an auto macro to run, it must
be either in the Normal template, in the active document, or in the template
on which the active document is based. "

For more info on auto macros, check the VBA help file on the subject.
--
Chuck Henrich
www.ProductivityApps.com
Stylist Style Generator - automatically create and define sets of paragraph
numbering and heading styles


"DualStar" wrote:

[Quoted Text]
> I created a new template based on an old template (same file name). I
> have renamed the command buttons so the code is easier to read (in the
> old template they were left at default CommandButton1, etc.)and added
> in some other functionality. Now I have a fully functional template for
> any future documents based on this template and it works fine. I didn't
> realize when you open a document based on a template none of the coding
> goes with it. Now when someone opens an old document that they have
> saved on their computer none of the command buttons work because (I
> think) it references the new template. Is there anyway to fix this? I
> have tried to open the old document and change the code for the command
> buttons in the referenced template file but that doesn't work. I have
> also tried to cut and paste the code into ThisDocument of the old
> document for a quick fix but that doesn't work either. Any help would
> be greatly appreciated. Thank you in advance.
>
>
Re: template change
"DualStar" <jallin[ at ]dualstar.ca> 02.02.2006 16:21:31
Thank you for your response. Alas, I did copy over the old file. I wish
this problem had occured to me sooner but unfortunately I just assumed
that the code was copied to the new document when based on a template.
Live and learn.

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net