Refer to network drive using network name instead of a mapped letter (eg "G:\")

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
At my work, the people who set up the computers used a lot of different letters to map the network.

I've tried using the path " \\networkname\ " in place of a letter, with no luck.

Any ideas?
 
All the answers I can find on the web are all about checking to see whether a file exists, and don't offer any information whatsoever about actually incorporating the UNC path into the open method's filename argument.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I've not used HP's suggestion of fchDirUNC, but it looks more direct than what I use to get a UNC path from a mapped drive:

Code:
Function Path2UNC(sFullName As String) As String
    ' Converts the mapped drive path in sFullName to a UNC path if one exists.
    ' If not, returns a null string
 
    Dim sDrive      As String
    Dim i           As Long
 
    sDrive = UCase(Left(sFullName, 2))
 
    With CreateObject("WScript.Network").EnumNetworkDrives
        For i = 0 To .Count - 1 Step 2
            If .Item(i) = sDrive Then
                Path2UNC = .Item(i + 1) & Mid(sFullName, 3)
                Exit For
            End If
        Next
    End With
End Function
So
Code:
    Dim sUNC As String
    
    sUNC = Path2UNC("X:\myPath\myFile.xls")
    If Len(Dir(sUNC)) Then
        Workbooks.Open sUNC
'        ...
    End With
 
Upvote 0
Like I said, I don't understand how to implement Hot Pepper's solution. I've been trying to figure it out all day.

It looks like your suggestion will only work if you already know the letter that the drive will be mapped to. Am I right about that?
 
Upvote 0
All the answers I can find on the web are all about checking to see whether a file exists, and don't offer any information whatsoever about actually incorporating the UNC path into the open method's filename argument
.

As far as I know you can use the UNC path in the open method's filename argument:

Workbooks.Open("\\server1\folder1\Book1.xls")

ξ
 
Upvote 0
Thanks for the reply, xenou. Somebody had changed the name of a folder in the path to my file since I last copied it down. I got it working now.

I never bothered to give it more than a cursory glance... especially after Hot Pepper's post, and the mob of hits on Google that say it's not possible to use UNC with either Dir or ChDir directly.

Thanks again.
 
Upvote 0
Just testing here at work:
Workbooks.Open(), DIR, and CHDIR all work with a UNC path. Google is wrong? {gasp}
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top