Reference anothet template

P

pfc

I am trying to create a reference to another template in VBA Tools ->
references. I can browse and apparently link successfully. When I
restart the Word session the link fails and I find it is pointing to
temp file on the M drive that doesn't exist. I can relink to the
correct template, which is also a global template and it functions
until I restart Word. Again it is pointing to a temp file that was
deleted when Word closed. Help please
 
J

Jonathan West

I am trying to create a reference to another template in VBA Tools ->
references. I can browse and apparently link successfully. When I
restart the Word session the link fails and I find it is pointing to
temp file on the M drive that doesn't exist. I can relink to the
correct template, which is also a global template and it functions
until I restart Word. Again it is pointing to a temp file that was
deleted when Word closed. Help please

Setting references to another template (as opposed to an ActiveX DLL) seems
to be a bit of a hit & miss affair. I would recommend that instead of
setting a reference, you load the other template as an add-in (this can be
done automatically when Word starts if you put the template in the Startup
folder), and then use the Application.Run method to call subroutines in the
add-in.

Working this way, you are not dependent on the reference working right in
terms of finding the actual location of the other template, but there are
other limitations you should be aware of. Primarily, Application.Run can
only call public Subs, it cannot call functions, class modules or UserForms
directly. You can pass parameters to these subs, and you can pass return
values back in those parameters.

Another possible approach is that you add the reference dynamically in code,
using the References.AddFromFile method. That way, you can at least check
that the file is where you think it is before adding the reference.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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