Getting a Workbooks path on a network (VBA)

ChrisOswald

Active Member
Joined
Jan 19, 2010
Messages
454
Running this code snippet with a workbook saved on a network drive:

Code:
StrThisSavePath = ActiveWorkbook.Fullname
debug.print StrThisSavePath

Returns something like

x:\Dist Doc Stg\Saved reports\...\MyDoc.xls
or
E:\Dist Doc Stg\Saved reports\...\MyDoc.xls

depending on how the network drive is mapped.

How would I get it the domain type of drive name thing?

i.e.

\\corpshare.mycompany.com\GRPS\Institutional\Dist Doc Stg\Saved reports\...\MyDoc.xls

Thanks,
Chris

ps. what is the correct way to say "domain type of drive name thing" ? I'd probably have had better luck with an internet search if I knew.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Uniform Naming Convention
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
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,787
Members
449,188
Latest member
Hoffk036

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