Get shared folders real path

H

HenrikH

Hi

I have a shared folder/drive called "H:". It points to the folder "\
\server\appl\gr-30\afd-53" on a shared drive.

So selecting the "H:" drive i explorer would show the files on "\
\server\appl\gr-30\afd-53" folder.

I want to get "gr-30" -part from the path and use it in a word macro.

Is this possible?
 
G

Graham Mayor

You want to extract the name of the folder above the current folder in the
document path?

Dim sPath As String
Dim vFolder As Variant
vFolder = Split(ActiveDocument.Path, "\")
sPath = vFolder(UBound(vFolder) - 1)
MsgBox sPath

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Tony Jollans

I'm not sure what you want here ...

.. is it always the top level directory within the share, or what?

.. where are you getting the path from in your code? Is it from the active
document as Graham suggests, or what?
 
J

Jay Freedman

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.
 
H

HenrikH

Thanks for all the answers.

Yes it could be difficult to figure out what I was looking for.

But Jay you hit it right on the spot - havent testet it fully (must
test it at work tomorrow) but it seems to do the trick

Thanks again to all...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top