Problem mapping drive through VBA

d_rose

New Member
Joined
Feb 24, 2004
Messages
1
I am using the following code to map a network drive:

Option Explicit

Private Declare Function WNetAddConnection Lib "mpr.dll" Alias _
"WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword _
As String, ByVal lpszLocalName As String) As Long

Sub Map()
Dim drive_letter As String
Dim share_name As String
Dim password As String
drive_letter = "V"
If InStr(drive_letter, ":") = 0 Then
drive_letter = drive_letter & ":"
share_name = "\\rtk001\foldername"
password = "password"

If WNetAddConnection(share_name, password, drive_letter) > 0 Then
MsgBox "Error mapping drive"
Else
MsgBox "Drive Mapped"
End If

End If
End Sub


The purpose of this macro is to map drive V to the server "rtk001". The macro is being run in various offices around the state; however, it is only working in my office building. It appears that my macro is not resolving the server name "rtk001" in these outside offices.

None of the offices have drive "V" mapped currently.

Please HELP!!!!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
WNetAddConnection is for 16-bit Windows, and perhaps
you should be using WNetAddConnection2 or WNetAddConnection3.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,085
Messages
5,857,273
Members
431,867
Latest member
Dalorian

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
Top