Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
Dim userResponce As String
Dim ExternalLinks As Variant
Dim x As Long
Dim wb As Workbook
Set wb = ActiveWorkbook
Repeat:
userResponce = Application.GetSaveAsFilename(InitialFileName:="%USERPROFILE%\Desktop\Monthly Sales Report - month year", _
fileFilter:="Excel Workbook(*.xlsx), *.xlsx")
If userResponce = "False" Then
Exit Sub
End If
userResponce = Right(userResponce, Len(userResponce) - InStrRev(userResponce, "\", -1, vbTextCompare))
On Error Resume Next
If Not IsDate(Split(Split(userResponce, "-")(1), ".")(0)) Then
If Err.Number or Len(Split(userResponce, "-")(1)) Then
MsgBox "Wrong file name"
GoTo Repeat
End If
End If
On Error GoTo 0
wb.Unprotect "1234"
wb.ActiveSheet.Unprotect "1234"
ExternalLinks = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
If IsArray(ExternalLinks) Then
For x = 1 To UBound(ExternalLinks)
wb.BreakLink Name:=ExternalLinks(x), Type:=xlLinkTypeExcelLinks
Next x
Application.EnableEvents = False
Application.DisplayAlerts = False
wb.SaveAs userResponce, FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
Application.EnableEvents = True
End If
End Sub