Excel VBA Tips: Closing All Non-Active Workbooks

By

Excel VBA Tips: Closing All Non-Active Workbooks

If you ever need to close off all the workbooks you have open in the background but don’t want to have to navigate to each one, this code is extremely useful.

Public Sub CloseAllInactive()

Dim Wb As Workbook
Dim AWb As String
AWb = ActiveWorkbook.Name

‘Your code here, or have this as a separate module

For Each Wb In Workbooks
If Wb.Name <> AWb Then
Wb.Close savechanges:=True ‘or False if you don’t want to save
End If
Next Wb

End Sub

Definitely helps save time if you do this on a regular basis.

Come check out the directory for the rest of my excel tips!

Submeg

IT