I'm not a VBA expert and get what I need from a combination of code I find on the Internet mixed with code created when recording macros. I'm stuck trying to figure something out. I have the code below that takes the active worksheet in a workbook, copies it to a new workbook, then opens a dialog box to save it as a CSV file. However, if I press the cancel button on the dialog box, it continues processing the code in the routine that calls this routine. I want it to just "End" if the user presses cancel. Any help is appreciated.
Code:
Sub SaveSheetAsCSV(Optional SheetToSave As Worksheet)
If SheetToSave Is Nothing Then Set SheetToSave = ActiveSheet
SheetToSave.Copy
If Not Application.Dialogs(xlDialogSaveAs).Show(, 6) Then
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub