I have created a form to save daily inspections using VBA and a Form Control Button (Save Form) based on the entry of a part# and date in two adjacent cells. The operator enters Part# in Cell B1 and Date in Cell B2 and selects the "Save Form" control button to unlock additional cells and start data entry.
If a duplicate form is attempted to be created/saved, the error message “A File Name \\xxx.xlsm already exists in this location. Do you want to replace it?” appears as expected.
When the user selects “No”, another Microsoft Visual Basic Message Box immediately appears indicating a Run Time has error has occurred because the form was not saved. The Message box requires the user to select “Debug, End or Help”
Is there any method to stop the MS VBA error message box from appearing after the user selects “No” upon receiving the initial error method?
Here is the code I am currently using to save the form:
Sub SaveWithVariableFromCell()
Dim SaveName As String
SaveName = ActiveSheet.Range("J2").Text
ActiveWorkbook.SaveAs Filename:="\\XXX\XXX\Completed Inspection Forms\" & _
SaveName & ".xlsm"
ActiveSheet.Protect DrawingObjects:=False, Contents:=False, Scenarios:=False
Range("C11:L130").Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveWorkbook.Save
End Sub
Bookmarks