We have a workbook, "followup_care.xlsm", in which data is moved to sheet "Done" and we like to move sheet "Done" to a new workbook ,saved with the date in the new workbook name, and both workbooks save and close.
Windows Excel 2007, 2010
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, cancel As Boolean)
Application.EnableEvents = False 'Stops the recursive saving
Application.DisplayAlerts = False 'Stops the prompt about overwriting the existing file.
If WorksheetFunction.CountA(Worksheets("Done").Range("A3,B3,C3,D3,E3, F3")) < 6 Then
MsgBox "Worksheet Done will not be moved to a backup file" & vbCrLf & _
"unless work on a complaint is completed!"
cancel = True
Sheets(2).Move
End If
original_name = "followup_care.xslm"
Workbooks(2).SaveAs "C:\PS2ndFloor\" & Format(Date, "mm-dd-yy-") & "PS2completed" & ".xls", FileFormat:=56
Workbooks(2).Close
Workbooks(ActiveWorkbook.Name).SaveAs "C:\PS2ndFloor\" & original_name
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub
Windows Excel 2007, 2010