ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   close all worksheets accept the active one (https://www.excelbanter.com/excel-programming/404304-close-all-worksheets-accept-active-one.html)

S Himmelrich

close all worksheets accept the active one
 
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?

Susan

close all worksheets accept the active one
 
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


On Jan 15, 3:20*pm, S Himmelrich wrote:
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?



XP

close all worksheets accept the active one
 
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


"S Himmelrich" wrote:

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?



All times are GMT +1. The time now is 07:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com