End Sub if network is down

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
I have code that sends data to our salesmans computers:

Code:
Select Case WB1.Sheets("FRONT").Range("C2").Value
        Case "MD"
            strfilename = "\\MIKESRGATEWAY\MikesProposals\" & strfilename
            
        Case "TD"
            strfilename = "\\Tomsblackibm\TomsProposals\" & strfilename
            
        Case "DJ"
            strfilename = "\\DAVEJONES\DavesProposals\" & strfilename
            
        Case "CP"
            strfilename = "\\Chuckscomputer\daily\" & strfilename
            
    End Select
    
    WB1.SaveCopyAs Filename:=strfilename
    
    WB1.ActiveSheet.Shapes("Button 53").Visible = False
    
    ChDir CurrPath

Sometimes if the salesmans computer is down, his computer is turned off, or there is network issues, I get an error on the line:
WB1.SaveCopyAs Filename:=strfilename
Is there a way to avoid this?? It is not imperative that the salesman recieves his copy on his computer, so if there is an error just end sub or something.

Thank You,
Michael
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Well, you could just skip the line if it errors:

Code:
On Error Resume Next 'if error occurs, continue macro

'if this line errors, code will continue instead of debugging
'because of the Resume Next
WB1.SaveCopyAs Filename:=strfilename

On Error Goto 0 'reset error trapping
 
Upvote 0
I would rather end the code, because I don't want to :
Make the button invisible

WB1.ActiveSheet.Shapes("Button 53").Visible = False

So I should use?? And where would be a good place?

Michael
 
Upvote 0
Oh, ok. You can still use the error trapping as above, but you can use a simple IF statement to end the macro rather than simply continuing the code:

Code:
On Error Resume Next 'if error occurs, continue macro

'if this line errors, code will continue instead of debugging
'because of the Resume Next
WB1.SaveCopyAs Filename:=strfilename

' check if error occured.
' If error occured, code ends.
' If no error, code continues
If Err.Number <> 0 Then Exit Sub

'reset error trapping
Err.Clear
On Error Goto 0
 
Upvote 0

Forum statistics

Threads
1,223,626
Messages
6,173,414
Members
452,514
Latest member
cjkelly15

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