close all worksheets accept the active one

  • Thread starter Thread starter S Himmelrich
  • Start date Start date
S

S Himmelrich

I've not seen anything on this, but would like to close all opened
worksheets accept the one that is current active - any thoughts on
this?
 
you mean close all other workBOOKS?
you can't close worksheets............

i would think it would be relatively simple - something like

for each workbook in excel.workbooks
if workbook.active=false then
OR if isnot activeworkbook then
(or something like that)
workbook.close
end if
next workbook

(this is just off the top of my head & syntax is probably terribly
wrong).
hth
susan
 
One way:

Call the function below like so (use true or false to save each one or not):

Sub Test()
Call FilesDeActivate(False)
End Sub


Public Function FilesDeActivate(argSaveChanges As Boolean)
Dim wrkBooks As Workbooks
Dim wrkBook As Workbook
Set wrkBooks = Application.Workbooks
For Each wrkBook In wrkBooks
If UCase(wrkBook.Name) <> UCase(ThisWorkbook.Name) Then
Workbooks(wrkBook.Name).Close SaveChanges:=argSaveChanges
End If
Next wrkBook
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top