View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JLatham JLatham is offline
external usenet poster
 
Posts: 2,203
Default How To Exit Macro Without Debug Prompting

Since you said that turning display alerts off is not an option. And if you
want it to be completely "quiet", delete my MsgBox line of code.

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...
On Error Resume Next
ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
If Err < 0 Then
'probably clicked [NO] in response to overwrite warning
'so just ignore the error and press on
MsgBox "Error: " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & _
"Encountered. File NOT saved.", vbOKOnly + vbCritical, "Error
Encountered"
Err.Clear
End If
On Error GoTo 0 ' clear error trapping
End If
End Sub


"GEdwards" wrote:

I am using a macro to save an XLS however if the file already exists you are
promted, as normal, if you want to replace the file or not (Yes or No). If I
choose "No" I just want to exit the macro however I am prompted with
"Continue, End or Debug".

How can I just exit from this macro gracefully? Turning "Display Alerts"
off is not an option, although it works. My code follows...

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub