Excel VisualBasic Script

Private Sub Workbook_BeforeClose(Cancel As Boolean)
           If Not ThisWorkbook.Saved Then
           ThisWorkbook.Save
           End If
     End Sub