Map drive to a local folder using vba

joshiroc

New Member
Joined
Dec 6, 2018
Messages
2
Hi all,

I've done a fair amount of searching and trying different methods myself; however, I am unable to map a drive letter to a local folder on my machine.

This thread shows how to map to a network drive, and it works well for actual network locations: https://www.mrexcel.com/forum/excel-questions/284297-map-network-drive-using-excel-macro.html

For mapping to a local folder, I can do this in CMD using subst, so I have tried several permutations of this code:

Code:
Private Sub mapdrive2()
    Dim MyDriveName As String
    Dim MyDrive As Object
    MyDriveName = """C:\Users\me\"""


    Call Shell("cmd.exe Subst N: " & MyDriveName, vbNormalFocus)
    
    '- error check
    If Err.Number <> 0 Then
        MsgBox (" Drive already mapped or not available ")
    Else
        MsgBox ("Mapped OK")
    End If
    Set MyDrive = Nothing


End Sub

This code opens CMD; however the N: drive is not 'mapped' and I can't seem to get it to work.

Any ideas for what to try?

Thanks,

Josh
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi Josh
Welcome to the board

Try:

Code:
Private Sub mapdrive2()
    Dim MyDriveName As String
    
    MyDriveName = "C:\Users\me"

    Call Shell("Subst N: " & MyDriveName, vbNormalFocus)
    
    '- error check
    If Err.Number <> 0 Then
        MsgBox (" Drive already mapped or not available ")
    Else
        MsgBox ("Mapped OK")
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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