Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default Current path to Qualified Path

Hi
How do I convert activeworkbook.path to a qualified network path.
activeworkbook.path = g:\mypath\myfile.xls
I want \\dfs01\shares\mypath\mypath.xls

Thanks
Mary
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Current path to Qualified Path

convert the drive letter to a UNC path and append the remainder of the path:

Option Explicit

Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCE_CONNECTED = &H1

Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long
End Type

Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias _
"WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, _
ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) _
As Long

Private Declare Function WNetEnumResource Lib "mpr.dll" Alias _
"WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, _
lpBuffer As Any, lpBufferSize As Long) As Long

Private Declare Function WNetCloseEnum Lib "mpr.dll" ( _
ByVal hEnum As Long) As Long

Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" _
(ByVal lpString As Any) As Long

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" _
(ByVal lpString1 As Any, ByVal lpString2 As Any) As Long

Sub GetNetDrives() ' demo of how to call function

Dim intIndex As Integer
Dim strBuf As String
Dim strLetter As String

For intIndex = 1 To 26
strLetter = Chr(intIndex + 64)
strBuf = strBuf & "Drive " & Chr(intIndex + 64) & ": " &
LetterToUNC(strLetter & ":") & vbNewLine
Next

MsgBox strBuf

End Sub


Function LetterToUNC(DriveLetter As String) As String
Dim hEnum As Long
Dim NetInfo(1023) As NETRESOURCE
Dim entries As Long
Dim nStatus As Long
Dim LocalName As String
Dim UNCName As String
Dim i As Long
Dim r As Long

' Begin the enumeration
nStatus = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, _
0&, ByVal 0&, hEnum)

LetterToUNC = "Drive Letter Not Found"

'Check for success from open enum
If ((nStatus = 0) And (hEnum < 0)) Then
' Set number of entries
entries = 1024

' Enumerate the resource
nStatus = WNetEnumResource(hEnum, entries, NetInfo(0), _
CLng(Len(NetInfo(0))) * 1024)

' Check for success
If nStatus = 0 Then
For i = 0 To entries - 1
' Get the local name
LocalName = ""
If NetInfo(i).lpLocalName < 0 Then
LocalName = Space(lstrlen(NetInfo(i).lpLocalName) + 1)
r = lstrcpy(LocalName, NetInfo(i).lpLocalName)
End If

' Strip null character from end
If Len(LocalName) < 0 Then
LocalName = Left(LocalName, (Len(LocalName) - 1))
End If

If UCase$(LocalName) = UCase$(DriveLetter) Then
' Get the remote name
UNCName = ""
If NetInfo(i).lpRemoteName < 0 Then
UNCName = Space(lstrlen(NetInfo(i).lpRemoteName) _
+ 1)
r = lstrcpy(UNCName, NetInfo(i).lpRemoteName)
End If

' Strip null character from end
If Len(UNCName) < 0 Then
UNCName = Left(UNCName, (Len(UNCName) _
- 1))
End If

' Return the UNC path to drive
LetterToUNC = UNCName

' Exit the loop
Exit For
End If
Next i
End If
End If

' End enumeration
nStatus = WNetCloseEnum(hEnum)

End Function

--
Regards,
Tom Ogilvy

"Mary" wrote in message
...
Hi
How do I convert activeworkbook.path to a qualified network path.
activeworkbook.path = g:\mypath\myfile.xls
I want \\dfs01\shares\mypath\mypath.xls

Thanks
Mary



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to view the path of current excel sheet? Sivagami Excel Discussion (Misc queries) 2 August 6th 08 10:26 AM
Accessing current project path Dhonan Excel Discussion (Misc queries) 0 August 15th 06 10:03 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
path to current file... daschund Excel Programming 1 August 31st 04 11:45 PM
Set The Directory to the Current WB Path Richy Excel Programming 2 February 29th 04 06:54 PM


All times are GMT +1. The time now is 07:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"