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!!!!
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,553
Messages
5,596,807
Members
414,104
Latest member
imamalidadashzada

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