Dear Experts,
I consistently receive many Excel report files with macros in them, but some files received have been mistakenly removed the macros due to saving them under .xlsx format.
For this reason, I've put the below macro in VBA Project Explorer - Workbook TAB to restrict saving the file in .xls. However there is a flaw in that this macro in that, when we save the file it will not prompt the default folder from which the file is opened, but prompt other folders especially when other workbooks are opened from "other" folders.
I've searched from internet and created a macro as below :
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strFileName As String
Const strRestrictedName As String = "False"
Application.EnableEvents = False
Cancel = True
strFileName = Application.GetSaveAsFilename(fileFilter:="Microsoft Office Excel Workbook (*.xls), *.xls")
If UCase$(strFileName) = UCase$(strRestrictedName) Then
MsgBox "Invalid File Name", vbCritical, "Stop"
Application.EnableEvents = True
ElseIf strFileName = "" Then
MsgBox "Invalid File Name", vbCritical, "Stop"
Application.EnableEvents = True
Else
ActiveWorkbook.SaveAs strFileName
Application.EnableEvents = True
End If
Application.EnableEvents = True
End Sub
Would like someone who can help fine-tune the scripts.
Many thanks !
Edward
Bookmarks