Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically set reference to global template?

Status
Not open for further replies.

tebathe3

Programmer
Jan 17, 2004
89
US
I need to call a method that accepts parameters which is located in a global template in Word (located in the user's startup directory for Word). I've learned that basically the only way to do this is for me to set a reference to the global file. All of our users *should* have this global file located on their system in the same location. However, I hate to assume this and have a macro that won't run because it can't find the necessary file. I'd like to have a variable grab the user's startup location and then dynamically add a reference to that file where the macro is located. Is this possible?
 
Use:

Options.DefaultFilePath(Path:=wdStartupPath)

Technically - if you want to be very explicit:

Application.Options.DefaultFilePath(Path:=wdStartupPath)

This is a string and can of course be used by any string variable.

Now I have a question. Yes, you can get a string variable of Startup; and so, yes, you can get a stringreference to the file. However, that does NOT make the code modules in that file directly accessible. You can of course code to them using VBAComponents. So I am not sure what you really mean by "dynamically add a reference to that file where the macro is located".

If the global is, in fact, global, then the code modules contained in are always accessible. I am not getting your problem.

Lastly, if you are in a networked environment, why not make the global sit on a server, and have it load from there? Then it becomes independent of the local machine.

Gerry
 
We unfortunatley have performance issues when we tried putting the templates out on the network.

I had read that the only way to pass parameters to a method located in a separate file is to add a reference to it. I got the info from this article. It's based on Project but the concepts should be the same:

 
This unfortunately a mis-use (IMHO) of the word "reference". Technically speaking, I believe a reference is a file that does NOT have to be explicitly open. DLL etc when made a reference do not actually open the file. Their contents are available, yes. Just a like a Word global template (if loaded) is not open, but the code contents are available. Now, yes, you can make a reference to a file dynamically - as suggested in that article. But note that the files are open.

So yeah, you could get the Startup location, and use it. But I think you have to open the file itself. You can not get at the code modules just knowing the file location. It is not a DLL.

Gerry
 
you can set a reference to a project though in the code window which is why i used the term reference.
 
Yes, but the project has to be available. And it is only available if the file is either open, or it is loaded as a global.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top