Map network drive using excel macro

BenjaminHusted

New Member
Joined
Oct 5, 2007
Messages
25
My corporate log-in script fails to map a key drive for me. The help desk is too back logged to change it, how can I use and excel macro to map it for me.

Thanks

Benjamin
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this.
Code:
'================================================================
'- MAP NETWORK DRIVE
'- if necessary map the drive by hand to see the correct name
'- it is not always the same as shown in Explorer
'- Brian Baulsom October 2007
'================================================================
'- does the job
Private Sub MapDrive()
    Dim MyDriveName As String
    MyDriveName = "\\Brian-dell\MY_FILES (F)"
    '------------------------------------------------------------
    '- map drive
    On Error Resume Next ' DRIVE MAY BE MAPPED ALREADY
    Set MyDrive = CreateObject("WScript.Network")
    MyDrive.MapNetworkDrive "F:", MyDriveName
    DoEvents
    '--------------------------------------------------------------
    '- error check
    If Err.Number <> 0 Then
        MsgBox (" Drive already mapped or not available ")
    Else
        MsgBox ("Mapped OK")
    End If
End Sub
'-------------------------------------------------------------------
 
Upvote 0
You are good my friend.

I just needed to add "Dim MyDrive As Object" and then dropped the letter reference from your loading of the "MyDriveName" variable.

Works like a charm.

Thank you for your help.



Public Sub MapDrive_Benjamin()


Dim MyDrive As Object
Dim MyDriveName As String

MyDriveName = "\\scns001a\ActuarialData"
'------------------------------------------------------------
'- map drive
On Error Resume Next ' DRIVE MAY BE MAPPED ALREADY
Set MyDrive = CreateObject("WScript.Network")
MyDrive.MapNetworkDrive "K:", MyDriveName
DoEvents
'--------------------------------------------------------------
'- 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,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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