Mapping network drive...

D

Dave Peterson

One more:

Option Explicit
Sub testme()
Dim res As Variant
res = TryToMapIt("G", "\\myserver\mypath")
If res = True Then
MsgBox "it worked"
Else
MsgBox res
End If
End Sub
Function TryToMapIt(myDrive, NewPath) As Variant

Dim FixedIt As Variant
Dim FSO As Object
Dim WSHNetwork As Object

Set WSHNetwork = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.driveexists(myDrive) Then
WSHNetwork.RemoveNetworkDrive myDrive, True, True
End If

FixedIt = False
On Error Resume Next
WSHNetwork.MapNetworkDrive myDrive, NewPath, True
If Err.Number = 0 Then
FixedIt = True
Else
If Err.Number <> 0 Then
FixedIt = Err.Description
End If
Err.Clear
End If

TryToMapIt = FixedIt

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top