VBA Code to map and unmap a drive in the system:
Sub Map_Drive()
Dim oNetwork As Object, sDrive As String, sPath As String
Set oNetwork = CreateObject("WScript.Network")
sDrive = "A:"
sPath = "\\Server1\ABC"
oNetwork.MapNetworkDrive sDrive, sPath
sDrive = "B:"
sPath = "\\Server2\XYZ"
oNetwork.MapNetworkDrive sDrive, sPath
End Sub
----------------------------------------------------------
Sub Unmap_Drive()
Dim objNetwork As Object
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemoveNetworkDrive "A:" ', bForce:=True
objNetwork.RemoveNetworkDrive "B:" ', bForce:=True
End Sub
VBA Function for RemoveNetworkDrive is as follows:
ReplyDeleteobject.RemoveNetworkDrive(strName, [bForce], [bUpdateProfile])
Example of using this function would be:
oNetwork.RemoveNetworkDrive ENTERDRIVELETTER ,true ,true