Reference in a dot file via code?

G

GrodanBoll

H

I have a lot of general code in a seperate dot file. Normally, I reference this file into another template in order to get access to its code
But my problem is that the location of the templates will not always be the same. The relative path will always be the same but not the absolute

So my question is: Are there any way that I can, via code, reference in the general dot file?
 
J

Jonathan West

Hi Grodan Boll,

The simplest approach that I can think of is to ensure the template is
loaded as an add-in, by installing it in Word's startup folder, and then
call routines in it by using the Application.Run command. Application.Run
doesn't care about where the template is located, so long as the template is
currently loaded

--
Regards
Jonathan West - Word MVP
http://www.multilinker.com
Please reply to the newsgroup

GrodanBoll said:
Hi

I have a lot of general code in a seperate dot file. Normally, I reference
this file into another template in order to get access to its code.
But my problem is that the location of the templates will not always be
the same. The relative path will always be the same but not the absolute.
So my question is: Are there any way that I can, via code, reference in
the general dot file?
 
P

Peter Hewett

Hi

Try the following:

ThisDocument.VBProject.References.AddFromFile "c:\Templates\My Lib.dot"

you'll obviously have to set the correct Add-In/path info.

HTH + Cheers - Peter
 
G

GrodanBoll

Hi

Thanks for your answer.
I implemented the code in this way:

Test01.dot
Code:
Private Sub Document_New()

Dim msgBoxen As Variant

ThisDocument.VBProject.References.AddFromFile Templates(1).Path & "\code.dot"

'msgBoxen = MsgBox(Templates(1).Path & "\code.dot is the path", vbCritical) ' Just to see if I get the correct path

Test 'Call to a sub defined in code.dot

End Sub

Code.dot (in a modul)
Code:
Public Sub Test()

Dim msgBoxen As Variant

msgBoxen = msgBox("Hello", vbCritical)

End Sub

When I try to use test01.dot as an template i get an error that says that the 'Test' sub is not defined.
Do I have to activate or load the reference in any way to make it work?

----- Peter Hewett wrote: -----

Hi

Try the following:

ThisDocument.VBProject.References.AddFromFile "c:\Templates\My Lib.dot"

you'll obviously have to set the correct Add-In/path info.

HTH + Cheers - Peter
 
T

Tom Winter

I'm not sure about the Reference stuff, but you can load the template as a
global add-in (Application.AddIns.Add...) and then call the macro using
Application.Run...
--
Tom Winter
(e-mail address removed)
www.AmosFiveSix.com

GrodanBoll said:
Hi

Thanks for your answer.
I implemented the code in this way:

Test01.dot
Code:
Private Sub Document_New()

Dim msgBoxen As Variant

ThisDocument.VBProject.References.AddFromFile Templates(1).Path & "\code.dot"

'msgBoxen = MsgBox(Templates(1).Path & "\code.dot is the path",[/QUOTE]
vbCritical) ' Just to see if I get the correct path[QUOTE]
Test 'Call to a sub defined in code.dot

End Sub

Code.dot (in a modul)
Code:
Public Sub Test()

Dim msgBoxen As Variant

msgBoxen = msgBox("Hello", vbCritical)

End Sub

When I try to use test01.dot as an template i get an error that says that the 'Test' sub is not defined.
Do I have to activate or load the reference in any way to make it work?

----- Peter Hewett wrote: -----

Hi

Try the following:

ThisDocument.VBProject.References.AddFromFile "c:\Templates\My Lib.dot"

you'll obviously have to set the correct Add-In/path info.

HTH + Cheers - Peter


in
Hi
reference this file into another template in order to get access to its
code. But my problem is that the location of the templates will not
always be the same. The relative path will always be the same but not
the absolute. reference in
the general dot file?
 

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