Managing errors

rhino4eva

Board Regular
Joined
Apr 1, 2009
Messages
238
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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

tyija1995

Well-known Member
Joined
Feb 26, 2019
Messages
781
Office Version
  1. 365
Platform
  1. Windows
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!
 

tyija1995

Well-known Member
Joined
Feb 26, 2019
Messages
781
Office Version
  1. 365
Platform
  1. Windows
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:

rhino4eva

Board Regular
Joined
Apr 1, 2009
Messages
238
just tried that ... IF T is mapped it closes and opens only T no mention of Z
 

rhino4eva

Board Regular
Joined
Apr 1, 2009
Messages
238
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
 

tyija1995

Well-known Member
Joined
Feb 26, 2019
Messages
781
Office Version
  1. 365
Platform
  1. Windows
Glad you got it to work!
Apologies I couldn't get to the final answer.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,598
Messages
5,832,646
Members
430,151
Latest member
Kacbear

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