Excel VBA - Return the Path Name of a Mapped Drive

dhancy

Board Regular
Joined
Jul 10, 2013
Messages
123
Office Version
  1. 365
Platform
  1. Windows
Hello.

I have this code to map a network drive to the W: drive:

VBA Code:
Dim MyDriveName As String
    MyDriveName = "[B]https://myPortal.com/sites/blahblahblah[/B]"
    Set MyDrive = CreateObject("WScript.Network")
    MyDrive.MapNetworkDrive "W:", MyDriveName

I now want to write additional code to return the path name that is associated with the W: drive.

I found this code:

Code:
Sub ShowDriveInfo()
    Dim fs, d, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    
    Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName("W:")))
    Debug.Print  d.ShareName
    
End Sub

But t returns this:

\\myPortal.com@SSL\DavWWWRoot\sites\blahblahblah

Is there similar code that will return https://myPortal.com/sites/blahblahblah instead?

Thanks!


Dennis
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello.

I have this code to map a network drive to the W: drive:

VBA Code:
Dim MyDriveName As String
    MyDriveName = "[B]https://myPortal.com/sites/blahblahblah[/B]"
    Set MyDrive = CreateObject("WScript.Network")
    MyDrive.MapNetworkDrive "W:", MyDriveName

I now want to write additional code to return the path name that is associated with the W: drive.

I found this code:

Code:
Sub ShowDriveInfo()
    Dim fs, d, s
    Set fs = CreateObject("Scripting.FileSystemObject")
   
    Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName("W:")))
    Debug.Print  d.ShareName
   
End Sub

But t returns this:

\\myPortal.com@SSL\DavWWWRoot\sites\blahblahblah

Is there similar code that will return https://myPortal.com/sites/blahblahblah instead?

Thanks!


Dennis
Why not just remove the \\ and append the result with https://? :)
 
Upvote 0
Then I would have:

https://myPortal.com@SSL\DavWWWRoot\sites\blahblahblah

instead of:



I guess my question is - Where did the "@SSL\DavWWWRoot" come from? And why does it have \ instead of / ?

Hmmm...
Sorry I was confused. The forward slash or simply slash is used in URL. For path and directory, the backslash is used. Since the code is to show path, the backslash is the correct notation.

The is directing to an IP address once translated by DNS. Not sure how you can map it as drive path.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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