Hi

I have a macro enabled workbook. In order to prevent overwriting I added following code to "ThisWorkbook":

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "Save functionality has been disabled!", vbInformation + vbOKOnly, Title:="Critical Error"
Cancel = True 'Following line will prevent all saving
End Sub


However at the end when the user closes the sheet I want them to be able to save after all under a certain preset name. To be able to do so I entered following code:

Private Sub Auto_Close()
Answer = MsgBox("Do you want to save the data for later use?" & vbCrLf & "If yes, please save under a different name!", vbQuestion + vbYesNo, "Save data for this supplier")
If Answer = vbNo Then
ThisWorkbook.Saved = True
Else
Set wb = ActiveWorkbook
strSC = Worksheets("Optimized_data").Range("D2").Value
strSN = Worksheets("Optimized_data").Range("E2").Value
strDag = Format(DateValue(Now), "YYYYMMDD")
strUur = Format(TimeValue(Now), "hhumm")
strFileSaveAs = Application.GetSaveAsFilename(InitialFileName:="Optimized Data - " & strSC & ", " & strSN & " - " & strDag & ", " & strUur, _
FileFilter:="(*.xlsm),*.xlsm", Title:="Save file as")
If strFileSaveAs <> "False" Then
wb.SaveAs strFileSaveAs 'Saves File
wb.Close 'Close File
Else
MsgBox "User cancelled!", vbCritical
Exit Sub
End If
End If
End Sub


Now the latter conflicts with the disabled save functionality off course. Is there a way I can allow Excel to save the file when the user clicks the "X"?

Thanks in advance for your help

Kind regards,
Tino XXL