Remove references to template

J

James H.

Hi all,

I've been writing Word templates with VBA for a little while, but have
never been able to fix the annoying problem (my home computer is running
WordXP on WinXP-Home while my work computer is running Word2K on
Win2K-Pro, both have Security set to Medium):

1. I create and save Simple.dot, a template which includes a simple macro.

2. I double-click Simple.dot to create a new document and save the
resulting file, IamSimple.doc.

3. Later, when I double-click IamSimple.doc to open the file, I get the
the message that C:\...\Simple.dot contains macros. As it turns out,
IamSimple.doc contains a reference to Simple.dot, and the Simple.dot
project is also open in the macro workspace.

The relevant macro code I have is the following ThisDocument code to
open the form:

Private Sub Document_New()

frm_Simple.Show

End Sub

Also, the following to close the form:

....
Unload frm_Simple
frm_Simple.Hide
....

Is there a piece of VBA code I can insert into my Simple.dot template to
remove all references to Simple.dot? I'd really rather not have someone
else open up IamSimple.dot on their machine and get that annoying
"contains macros" messages.

Thanks,

James
 
J

Jean-Guy Marcil

James H. was telling us:
James H. nous racontait que :
Hi all,

I've been writing Word templates with VBA for a little while, but have
never been able to fix the annoying problem (my home computer is
running WordXP on WinXP-Home while my work computer is running Word2K
on Win2K-Pro, both have Security set to Medium):

1. I create and save Simple.dot, a template which includes a simple
macro.
2. I double-click Simple.dot to create a new document and save the
resulting file, IamSimple.doc.

3. Later, when I double-click IamSimple.doc to open the file, I get
the the message that C:\...\Simple.dot contains macros. As it turns
out, IamSimple.doc contains a reference to Simple.dot, and the
Simple.dot project is also open in the macro workspace.

The relevant macro code I have is the following ThisDocument code to
open the form:

Private Sub Document_New()

frm_Simple.Show

End Sub

Also, the following to close the form:

...
Unload frm_Simple
frm_Simple.Hide
...

Is there a piece of VBA code I can insert into my Simple.dot template
to remove all references to Simple.dot? I'd really rather not have
someone else open up IamSimple.dot on their machine and get that
annoying "contains macros" messages.

If, after creating the doc from the dot, the macro connection and other
links to the template are not needed, just attach the doc to Normal.dot
after creating it.

You will then lose all connection to the macros, custom toolbars, autotexts,
etc, from the Simple.dot template.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

James H.

Jean-Guy Marcil said:
If, after creating the doc from the dot, the macro connection and other
links to the template are not needed, just attach the doc to Normal.dot
after creating it.

You will then lose all connection to the macros, custom toolbars, autotexts,
etc, from the Simple.dot template.

Thanks for your quick reply, Jean-Guy! How do I attach the doc to
Normal.dot?

I was hoping for something a little simpler for end-users, but if that's
the only (or easiest) solution, then I guess I'll have to do it that way
(and instruct my end-users to do the same).

Thanks,

James
 
J

Jean-Guy Marcil

James H. was telling us:
James H. nous racontait que :
Thanks for your quick reply, Jean-Guy! How do I attach the doc to
Normal.dot?

I was hoping for something a little simpler for end-users, but if
that's the only (or easiest) solution, then I guess I'll have to do
it that way (and instruct my end-users to do the same).

It depends on how the doc is created/distributed and when in the process the
connection to the template must be cut.

Meanwhile, if you want to do it through VBA, look at the
.AttachedTemplate
property in the VBA help.

Otherwise, manually, it is in Tools > Templates & Add-Ins..., under the
Document Template section at the top of the dialog.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

James said:
Thanks for your quick reply, Jean-Guy! How do I attach the doc to
Normal.dot?

I was hoping for something a little simpler for end-users, but if
that's the only (or easiest) solution, then I guess I'll have to do
it that way (and instruct my end-users to do the same).

Thanks,

James

Hi James,

Add this as the last line of your AutoNew macro before the End Sub:

ActiveDocument.AttachedTemplate = Application.NormalTemplate

The userform will run, it will do whatever processing it has to do, and
close; then the document will disconnect from Simple.dot and be attached to
Normal.dot instead. The users don't need to know or do anything.
 
J

James H.

Jay said:
Hi James,

Add this as the last line of your AutoNew macro before the End Sub:

ActiveDocument.AttachedTemplate = Application.NormalTemplate

The userform will run, it will do whatever processing it has to do, and
close; then the document will disconnect from Simple.dot and be attached to
Normal.dot instead. The users don't need to know or do anything.

Hi Jay & Jean-Guy,

Thanks for your responses. ActiveDocument.AttachedTemplate took care of
the problem. As suggested, I added it at the end wherever I have the
close form code, and it worked like a charm:

....
Unload frm_Simple
frm_Simple.Hide
ActiveDocument.AttachedTemplate = Application.NormalTemplate
....

Thanks,

James
 
K

Klaus Linke

Hi James,

Another thing: Where is the attached template stored?
If it's in the user or workgroup template directory, it should be "trusted" and
shouldn't raise the macro warning.

Might be the easier way out of your problem in the future...

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top