Determine location of base document via VBA?

J

Jason McClean

HI,

I have several documents that have a Document_new() sub. When this is
executed (after a new document is created based on the original), the macro
extracts the path from the original document name, on which all other paths
in macros within the document are based.

If the original file is a template then this information can be gleaned from
ActiveDocument.AttachedTemplate.Path, but if the original document is a DOC
file, how could I do this?

The reason is that on opening the new document, macro code is imported from
bas & frm files from a relative path to the original document. I have
several servers where these documents are homed. The are connected via WAN
links, but the imported files must be read locally otherwise I have speed
implications (they would work but be very slooowwww).

Obviously, I could just make sure that the original files are all template
files (and I wish they were), but is there any other way in code to get this
information?

e.g.

original file : \\myserver\d\docs\myfile.doc

I create a new file based on the original which would then import files from
\\myserver\d\macros\import.

I don't want to hard code the paths in, so when I copy the file to
\\MySecondServer\e, the import files are read from
\\MySecondServer\e\macros\import

The reason I import code is so that I only have to maintain those files, so
everytime a new document is created, it runs the most up to date macros read
from the imported files.

Any ideas?

Cheers.

Jason
 
M

martinique

If your new document is based on an existing document, what triggers the
Document_New() event? If you open the existing document then do a SaveAs,
from Word's point of view, there's no new document involved.

However, assuming you have a way to get your code to run, one approach would
be to add some code to the Document_Open() event (fired when you open the
existing document) -- at this point, save the document's FullName (or the
path segment of it) to a document variable. Your other code can retrieve the
value from there.
 
J

Jason McClean

If you right click on a normal document, you have the option to create a new
document based on that document. A database application that we use happens
to make use of that feature. That is what triggers the event.
 
J

Jason McClean

Interseting idea, never thought of that. I have, however, decided to go
down the proper route and convert the docs to dots. Not a great deal of
hassle, just slow over the WAN link.

Cheers for the suggestion though, it may come in handy in the future.

Jason.
 

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