Consulting

Results 1 to 5 of 5

Thread: How to obtain the file path to a shortcut from which ActiveDocument was launched?

  1. #1

    How to obtain the file path to a shortcut from which ActiveDocument was launched?

    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 here: http://stackoverflow.com/questions/4...he-activedocum

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    992
    Location
    Maybe [VBA]Debug.Print Application.Templates(ActiveDocument.AttachedTemplate).Path[/VBA]

    David

    David


  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    Careful. That would give the path to the template itself. This may, or may not, be the path to the shortcut. It depends on whether it really is a shortcut.

    If the sub-folder has the template file itself, then clicking on it is NOT clicking on a shortcut.

  4. #4
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    I don't think what you're asking is possible from within the VBA environment. Word doesn't know that a shortcut launched it, as the shortcut is something in the file system... Word just knows that a Document New call was placed to the template.

    You would probably need to set up some kind of batch file which calls the template and also writes the current directory into some location (regkey, textfile, etc). Then within VBA you could obviously check the regkey/text file values to see where the batch file wrote from.

    But that kind of "exactly where did I start from" info doesn't get passed along to Word, it just knows what document is open, and what (if any) the attached template is.

    Hope that helps.

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    If it was, in fact, a shortcut. We do not know that for a fact.

    We need to know what EXACTLY is happening. Why would you put a shortcut - a real Windows shortcut - in the folder like that? But, if it is one, then the issue I stated, and restated (better) by Frosty applies.

    Using VBA to get the path to the template gets the path to the template, NOT the path to the shortcut. If the folder that contains the (Windows) shortcut is what is needed, then VBA by itself can not get it. Even using a batch file, while it would work, would probably need to be hard-coded - ie. a shortcut in U:\Whatever\Yadda would need a batch file that explicitly had U:\Whatever\Yadda.

    THAT could rapidly become a pain.

    So. Is it a real shortcut, or not?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •