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

Posted by:submeg

Musician, Writer and Inspirer. I discuss the projects I am working on, the services I provide and my general thoughts.

Tell me what you think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s