开发者

Visual Basic in Word 2010 - Open Dir - Relative Path

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 w开发者_C百科ith 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?


I think something like this might be what you're looking for:

FolderName = ActiveDocument.Path & "\SubFolder"

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

Assuming that your document is the active one, otherwise you might need to search through the Documents collection for the correct one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜