Hi all, please can somebody advise me where I am going wrong, I have an Excel file put together in Excel 2002/2003 using xls.
I have upgraded to Office 2010 and instead of using the original xls version have saved the file as an xlsb binary version purely because the file can be around 30Mb or higher depending how many worksheets are added.
While using the xls file, when I press the "SaveAs" button, the file would SaveAs a specific filename without any warnings in the same folder as the original.
Now I have upgraded, I am having issues where the file appears to save but in reality does not.
I have looked on the web to see that a file format number must be used - 50 and have included this in the code but still nothing happens.
Am I writing something wrong.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim FilePath As String, NewFileName As String, FileExtStr As String, FileFormatNum As Integer
Dim CurrentFileName As String
CurrentFileName = ThisWorkbook.Name
Cancel = True
Select Case SaveAsUI
Case False
ThisWorkbook.Save
Case True
FilePath = ThisWorkbook.Path
NewFileName = "Workfile - Backup"
FileExtStr = ".xlsb"
FileFormatNum = 50
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FilePath & "\" & NewFileName & FileExtStr, FileFormat:=FileFormatNum
MsgBox "A copy of """ & CurrentFileName & """" & " is now saved in the same directory, called: """ & NewFileName & FileExtStr & """.", vbInformation, " Backup Success"
End Select
Application.DisplayAlerts = True
End Sub
By pressing "Save" will save the open file as normal.
By pressing "SaveAs" will save the open file with a filename with backup in its title without any warning messages of overwriting etc.
Hope somebody can help.
Bookmarks