mweidner
asked on
Adding error code to Excel macro
How do I put error code in this macro. If the file already exsists and I select "NO" do not overright I get an error where to macro should just terminate.
Sub SaveQuit()
Dim Response As Integer
ThisFile = Range("k19").Value
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=52
' Displays a message box with the yes and no options.
Response = MsgBox(prompt:="Quit Program?", Buttons:=vbYesNo)
' If statement to check if the yes button was selected.
If Response = vbYes Then
Application.Quit
Else
' The no button was selected.
End If
End Sub
Sub SaveQuit()
Dim Response As Integer
ThisFile = Range("k19").Value
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=52
' Displays a message box with the yes and no options.
Response = MsgBox(prompt:="Quit Program?", Buttons:=vbYesNo)
' If statement to check if the yes button was selected.
If Response = vbYes Then
Application.Quit
Else
' The no button was selected.
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry on last thread try it
If Dir(ThisFile) <> "" Then then
If MsgBox(prompt:="Quit Program?", Buttons:=vbYesNo) = vbYes Then
Application.Quit
else
Kill (ThisFile)
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=52
end if
end if
If Dir(ThisFile) <> "" Then then
If MsgBox(prompt:="Quit Program?", Buttons:=vbYesNo) = vbYes Then
Application.Quit
else
Kill (ThisFile)
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=52
end if
end if
If Dir(ThisFile) <> "" Then Kill (ThisFile) then
If MsgBox(prompt:="Quit Program?", Buttons:=vbYesNo) = vbYes Then
Application.Quit
else
ActiveWorkbook.SaveAs Filename:=ThisFile, FileFormat:=52
end if
end if