Visual Basic in Word 2010 - Open Dir - Relative Path RRS feed

  • Question

  • Hi There,

    I'm creating a word document and I'm having trouble working out the code to open a specific directory. Basically, I'll have a bunch of video files on a USB drive or a DVD in separate folders and when the command button is clicked, I would like it to open the relevant directory in a windows explorer window.

    I did some Google searching and came up with the following code:

    FolderName = "c:\windows"

    TaskID = Shell("explorer.exe " & FolderName, vbNormalFocus)

    The only problem now is that I need to change the path reference from absolute to relative, as I'll be running everything from either a USB drive or a DVD on multiple computers.

    I have tried every possible iteration of relative path references, but I can't seem to get it to work. The folders are simply sub-directories of where the word document is.

    Anyone got any clues as how I can change the above code to be relative rather than absolute path references?



    • Moved by Mike Feng Monday, October 17, 2011 8:15 AM VBA (From:Visual Basic General)
    Friday, October 14, 2011 12:23 AM


  • Hi

    If you are looking for a path relative to the current document .. you can use

    FolderName = ActiveDocument.Path

    TaskID = Shell("explorer.exe " & FolderName, vbNormalFocus)

    Or if you have this code in a Template/Addin and want to get the relative path of the addin then


    FolderName = ThisDocument.Path

    TaskID = Shell("explorer.exe " & FolderName, vbNormalFocus)




    Monday, October 17, 2011 10:51 AM

All replies