I’ve noticed many people trying to find code that on closing a workbook will prompt to save (if changes were made) and then close the workbook and close Excel. The following code should do the trick.
Place this code in a module and link to a command button or shape
Sub CloseWkBk()
ActiveWorkbook.Close
End Sub
*******************************************
Place the code below in ThisWorkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wBook As Workbook
Dim LCount As Long
If Cancel = False Then
For Each wBook In Workbooks
If wBook.Name <> Me.Name And UCase(wBook.Name) <> "PERSONAL.XLS" Then
LCount = LCount + 1
End If
Next wBook
If LCount = 0 Then Application.Quit
End If
End Sub
Place this code in a module and link to a command button or shape
Sub CloseWkBk()
ActiveWorkbook.Close
End Sub
*******************************************
Place the code below in ThisWorkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wBook As Workbook
Dim LCount As Long
If Cancel = False Then
For Each wBook In Workbooks
If wBook.Name <> Me.Name And UCase(wBook.Name) <> "PERSONAL.XLS" Then
LCount = LCount + 1
End If
Next wBook
If LCount = 0 Then Application.Quit
End If
End Sub