Graham, if the document is opened through a mapped drive letter (in this
example, "H:\") then ActiveDocument.Path will contain just that letter and
the colon.
Henrik, here's some code slightly modified from
http://support.microsoft.com/kb/160529. It has been tested only in Word 2003
on Windows XP, but I believe it will work in all versions of Word from Word
97 onward, and all versions of Windows from Windows 2000 onward.
You should be able to use pathNodes(4) for whatever your purpose is -- see
the comments in the code.
Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
lpszRemoteName As String, lSize As Long) As Long
' Use for the return value of WNetGetConnection() API.
Const NO_ERROR As Long = 0
' The size used for the string buffer. Adjust this if you
' need a larger buffer.
Const lBUFFER_SIZE As Long = 255
Sub GetNetPath()
Dim DriveLetter As String
Dim lpszRemoteName As String
Dim cbRemoteName As Long
Dim lStatus As Long
Dim pathNodes As Variant
DriveLetter = "H:"
' Specifies the size in characters of the buffer.
cbRemoteName = lBUFFER_SIZE
' Prepare a string variable by padding spaces.
lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)
' Return the UNC path (\\Server\Share).
lStatus& = WNetGetConnection32(DriveLetter, lpszRemoteName, _
cbRemoteName)
' Verify that the WNetGetConnection() succeeded.
' WNetGetConnection() returns 0 (NO_ERROR) if it successfully
' retrieves the UNC path.
If lStatus& = NO_ERROR Then
' optionally display the UNC path.
MsgBox lpszRemoteName, vbInformation
pathNodes = Split(lpszRemoteName, "\")
MsgBox pathNodes(4)
' After the Split, pathNodes(1) will be an empty string
' (the 'nothing' between the first two backslashes) and
' pathNodes(2) will be the server name; the rest of the
' nodes will follow in sequence after that.
Else
' Unable to obtain the UNC path.
MsgBox "Unable to obtain the UNC path.", vbInformation
End If
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.