Add-Ins

J

jag

I have several template files where each template is different, but most of
the code in each is the same. Everytime I need to modify one of the
userforms or something in the files I have to make the change in each file.
I want to be able to have a central code template that all these files can
share to get the "common" code from.

I attempted this by creating a "code" template that had the userforms and
code that all the files would share. I then went into one of the template
files and under Tools, Templates and Add-Ins, inserted my "code" template
into the list.

I can now see the "code" template listed in my VB project window, but have
two issues.

1. If I try and expand the "code" template in the project window, I get an
error message, "Project is unviewable". What have I done wrong???
2. How do I reference the userforms, subs, etc. that I need from the "code"
template.

Hope this makes sense,
Thanks for your help..
jag
 
A

Anne P.

Answers to your questions are:

First, if you place the "code template" in your startup directory, you won't
need to go into Templates and Addins to add it. It will load every time a
user opens Word.

Second, if you want to edit the code in this template, it will appear in the
Project Explorer in the VB Editor, but you can't edit the code because it is
loaded. You have to "Open" the template so that you may make edits to the
code. In Windows Explorer, navigate to your Startup directory, right-click
over the name of the "code template" and choose Open. If you double-click
the template name, you will still not be able to make edits to the code. By
the way, when you do it this way, if you make changes and save it the
changes are made immediately to the copy that is in the Startup directory.
If you want to make any changes and test them first, you might want to copy
this template to a different directory before opening.

Third, I just learned this myself: You have various templates (i.e.,
Letter.dot, Memo.dot, Fax.dot) that you need to use the code from the "code
template" to complete the documents. In any version of Windows before
Windows 2000, you would open the VB Editor and choose Tools, References,
then locate the "code template" and check the box next to it (you would have
to do this in each template that you wanted to be able to grab code from the
"code template". That was when the startup directory was the same for all
users (something like: C:\Program Files\Microsoft Office\Office9\Startup).
Now the location is different for each user because it is under Documents
and Settings/username/ etc..... I just recently found out that all I have
to do to call the code from the global template is this:

Application.Run globaltemplatename.modulename.procedurename

Hope this helps.

Anne P.
 
T

Tabasco Ed

Answers to your questions are:

First, if you place the "code template" in your startup directory, you won't
need to go into Templates and Addins to add it. It will load every time a
Second, if you want to edit the code in this template, it will appear in the
Project Explorer in the VB Editor, but you can't edit the code because it is
loaded. You have to "Open" the template so that you may make edits to the
code.

This can be very confusing to someone who only uses Excel. In Excel,
you can edit the code on any loaded add-in. You don't have to open
the file first. I get confused when I start working in Word after
working in Excel for a while - I forget that I have to open the file
first. Why Microsoft made Excel and Word work differently in this
respect, I don't understand.
 
J

jag

Thanks for the info, couple of things.

I understand I can't edit the "code template" unless I have the it open.
How do I reference the subs in my "code template" from within my working
template?
Also, these files will be passed out to users at different locations, what
is the best way to find out what their startup location is?

thanks
 
A

Anne P.

Hi, jag,

I was having the same problem with referencing code from a global template
in other templates. Charles Kenyon and Jonathan West helped me out with
that. You don't need to know where the other user's startup location is.
You reference a piece of code like so:

Application.Run macroname:="mycodetemplate.mymodule.macroname".

For more information, look at the thread from my question, "How to call
macros and userforms from another template" on 6/8/2005.

Charles and Jonathan were very helpful there.

Anne P.
 

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