Managing errors

rhino4eva

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

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

tyija1995

Well-known Member
Joined
Feb 26, 2019
Messages
766
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
766
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
234
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
234
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
766
Office Version
  1. 365
Platform
  1. Windows
Glad you got it to work!
Apologies I couldn't get to the final answer.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,624
Messages
5,523,968
Members
409,547
Latest member
AW2020

This Week's Hot Topics

Top