Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False
Cancel = True
Dim saveas As String
If SaveAsUI = True Then
saveas = Application.GetSaveAsFilename(filefilter:="Microsoft Excel Workbook (*.xls), *.xls")
If saveas = "False" Then
Application.EnableEvents = True
Exit Sub
End If
Else
saveas = "Normal"
End If
If saveas = "Normal" Then
If ThisWorkbook.Name <> "Sheet Name.xls" Then
MsgBox "Illegal filename!!!" & vbCrLf & "The filename must be Sheet Name.xls", vbCritical, "Error"
Application.EnableEvents = True
Exit Sub
Else
Me.Save
End If
Else
If saveas <> ThisWorkbook.Path & "\Sheet Name.xls" Then
MsgBox "Illegal filename!!!" & vbCrLf & "The filename must be Sheet Name.xls", vbCritical, "Error"
Application.EnableEvents = True
Exit Sub
Else
Me.saveas saveas
End If
End If
Me.Saved = True
Cancel = False
Application.EnableEvents = True
End Sub