Managing errors

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
260
Office Version
  1. 2010
Platform
  1. Windows
Sub opensezAme(sPATH, sDrive As String)

Dim TPATH As Object
Set TPATH = CreateObject("WScript.Network")
On Error Resume Next
TPATH.MapNetworkDrive sPATH, sDrive

End Sub
------------------------------------------------------
Sub closesezAme(sDrive As String)

Shell "net use " & sDrive & ": /delete /y"

End Sub
------------------------------------------------------
Sub openup()

Call opensezAme("T:", "\\tpslth\hfs\mic")
Call opensezAme("Z:", "\\pcr\micropcr$")
End Sub
------------------------------------------------------
Sub closeup()

Call closesezAme("T")
Call closesezAme("Z")
End Sub
------------------------------------------------------

as you can see I have 4 subs one of which is a variable controlled engine.
I need to modify the "on ERROR" line to detect if the drives are all ready mapped and If so run CLOSEUP then run OPENUP

I don't know enough about error config so any help would be appreciated
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi rhino,
try use this instead:

Code:
Sub opensezAme(sPATH, sDrive As String)


Dim TPATH As Object
Set TPATH = CreateObject("WScript.Network")
On Error GoTo runOpenAndClose
TPATH.MapNetworkDrive sPATH, sDrive


runOpenAndClose:
    Call closeup
    Call openup
End Sub

Let me know if it works or not!
 
Upvote 0
Apologies there should be an End just before the runOpenAndClose label!!

Code:
Sub opensezAme(sPATH, sDrive As String)

Dim TPATH As Object
Set TPATH = CreateObject("WScript.Network")
On Error GoTo runOpenAndClose
TPATH.MapNetworkDrive sPATH, sDrive

End

runOpenAndClose:
    Call closeup
    Call openup
End Sub
 
Last edited:
Upvote 0
just tried that ... IF T is mapped it closes and opens only T no mention of Z
 
Upvote 0
have moved a few things round and managed to make it work


Sub openengine(sPATH, sDrive As String)

Dim TPATH As Object
Set TPATH = CreateObject("WScript.Network")
On Error GoTo runCloseAndOpen
TPATH.MapNetworkDrive sPATH, sDrive
End
runCloseAndOpen:
Shell "net use T: /delete /y"
Shell "net use Z: /delete /y"
Application.Wait (Now + #12:00:02 AM#)
TPATH.MapNetworkDrive "T:", "\\tpslth\hfs\mic"
TPATH.MapNetworkDrive "Z:", "\\pcr\micropcr$"
Application.Wait (Now + #12:00:02 AM#)

End Sub
Sub closeDRIVES()

Shell "net use T: /delete /y"
Shell "net use Z: /delete /y"

End Sub
Sub openDRIVES()

Call openengine("T:", "\\tpslth\hfs\mic")
Call openengine("Z:", "\\pcr\micropcr$")

End Sub

thanks for the pointer
 
Upvote 0
Glad you got it to work!
Apologies I couldn't get to the final answer.
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,814
Members
448,990
Latest member
rohitsomani

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
Back
Top