How do I use VBA to obtain the file path to a shortcut from which the ActiveDocument was launched?

1.5k views Asked by At

I am building a document management system. In each subdirectory within the main document repository, there is a shortcut to a document template. When a user wants to create a new document, he/she navigates to the appropriate subdirectory for the document and clicks the shortcut.

When the user clicks the shortcut, MS Word is launched, showing the new document based on the template. When the user clicks Save, the document will normally be saved to the current directory which will be the default location for new documents specified in Word Options.

I want the current directory of a new document to be the same as the directory of the shortcut from which it was created. The user has already decided where the document is to be located by navigating to the appropriate subdirectory and clicking the shortcut. It should not be necessary for the user to navigate to the same location again within the Save As... dialog.

If I can obtain the path to the shortcut, I can programmatically save the document to the same directory or a new subdirectory.

Also asked on MSDN VBA Forum and on VBA Express.

2

There are 2 answers

1
Chris Rae On BEST ANSWER

I don't think you're going to be able to do this without doing some awful hacking around trawling the file system (I had a brainwave about the "Start in" property of the shortcut, but sadly that didn't work).

Unfortunately I think the best solution may be to get rid of the shortcuts and just have lots of copies of the document template lying around.

Chris

1
Tiago Cardoso On

Maybe this?

Public Sub OriginalPath()

    Debug.Print TemplateProject.ThisDocument.Path

End Sub