Excel VBA Tips: Closing All Non-Active Workbooks

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

About these ads

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

  • Views:

    • 257,759 hits
  • submeg.fm: 30,377 songs 6,160 artists
    AND GROWING...
Follow

Get every new post delivered to your Inbox.

Join 830 other followers

%d bloggers like this: