If I run the following, it works and removes the network drive,
Set objNet = CreateObject("WScript.Network")
objNet.RemoveNetworkDrive "A:"
However if I run this,
If Len(Dir("A:\", vbDirectory)) > 0 Then
Set objNet = CreateObject("WScript.Network")
objNet.RemoveNetworkDrive "A:"
End If
I get the following error,
"This network connection has files open or requests pending"
CodePudding user response:
Don't use Dir
, try this:
Set fso = CreateObject("scripting.filesystemobject")
If fso.DriveExists("A") Then
Set objNet = CreateObject("WScript.Network")
objNet.RemoveNetworkDrive "A:"
End If