I have a simple macro (below) that copies a worksheet to a new file and saves it.
I have noticed there are two problems (at least) that can cause an error:
1) There is a file already open with the same name
2) The user is not authorized to save in the current directory
I have not used "error handling" code and I wonder if anyone could help. Does each of these errors have a Microsoft error number, or something like that?
Ideally I would like a message box that explains the error to the user, then quits the macro on "OK".
Thanks,
MikeG
Sub Save_Quote()
' Save_Quote Macro
Dim wbNew As Workbook
ThisWorkbook.Worksheets("Create Or Modify A Quote").Copy
Set wbNew = ActiveWorkbook
With wbNew
.SaveAs Filename:=Range("Quote_Save_Name") & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
.Close
End With
End Sub
I have noticed there are two problems (at least) that can cause an error:
1) There is a file already open with the same name
2) The user is not authorized to save in the current directory
I have not used "error handling" code and I wonder if anyone could help. Does each of these errors have a Microsoft error number, or something like that?
Ideally I would like a message box that explains the error to the user, then quits the macro on "OK".
Thanks,
MikeG
Sub Save_Quote()
' Save_Quote Macro
Dim wbNew As Workbook
ThisWorkbook.Worksheets("Create Or Modify A Quote").Copy
Set wbNew = ActiveWorkbook
With wbNew
.SaveAs Filename:=Range("Quote_Save_Name") & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
.Close
End With
End Sub