XLA routines: EE_CloseOtherWorkbooks

Nick's picture
Routine to close other workbooks - this saves setting variables and tracking open workbooks
Sub EE_CloseOtherWorkbooks(wbKeepOpen As Workbook)
'http://excelexperts.com/xla-routines-eeCloseOtherWorkbooks    for updates on this sub routine
' closes workbooks other than the workbook containing the code and another one specified
Dim wbk As Workbook
 
 
    On Error Resume Next
    For Each wbk In Application.Workbooks
        If wbk.Name <> ThisWorkbook.Name Then
            If Not wbKeepOpen Is Nothing Then
                If wbk.Name <> wbKeepOpen.Name Then
                    wbk.Close (False)
                End If
            End If
        End If
    Next
End Sub