ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   closing all files (https://www.excelbanter.com/excel-programming/371226-closing-all-files.html)

colt

closing all files
 
how can i close all open office files as i close current active workbook?


Jean-Yves[_2_]

closing all files
 
HI,

Keep shift key pressed, menu File/Close all
or
Private Sub Workbook_BeforeClose(Cancel As Boolean)

dim wb as workbook
for each wb in workbooks
if wb.name < thisworkbook.namen then wb.close False 'close without save
next
End Sub

Put this in the Thisworkbook module
Regards
JY

"colt" wrote in message
...
how can i close all open office files as i close current active workbook?




Muhammed Rafeek M

closing all files
 
try this macro

Sub CloseAllWorkbook()
Dim i As Integer
For i = Workbooks.Count To 1 Step -1
If ThisWorkbook.Name < Workbooks(i).Name Then
Workbooks(i).Close
End If
Next i
End Sub


"Jean-Yves" wrote:

HI,

Keep shift key pressed, menu File/Close all
or
Private Sub Workbook_BeforeClose(Cancel As Boolean)

dim wb as workbook
for each wb in workbooks
if wb.name < thisworkbook.namen then wb.close False 'close without save
next
End Sub

Put this in the Thisworkbook module
Regards
JY

"colt" wrote in message
...
how can i close all open office files as i close current active workbook?





colt

closing all files
 
Hi Jean-Yves
thanks so much - i have been working on this problem for some time.
I needed the code version and I just got it to work - so excited.
kindest regards colt.

"Jean-Yves" wrote:

HI,

Keep shift key pressed, menu File/Close all
or
Private Sub Workbook_BeforeClose(Cancel As Boolean)

dim wb as workbook
for each wb in workbooks
if wb.name < thisworkbook.namen then wb.close False 'close without save
next
End Sub

Put this in the Thisworkbook module
Regards
JY

"colt" wrote in message
...
how can i close all open office files as i close current active workbook?





colt

closing all files
 
thanks Muhammed
this code works well
many thanks for your response
I have now overcome a hurdle in my application which has taken some time.
regards colt

"Muhammed Rafeek M" wrote:

try this macro

Sub CloseAllWorkbook()
Dim i As Integer
For i = Workbooks.Count To 1 Step -1
If ThisWorkbook.Name < Workbooks(i).Name Then
Workbooks(i).Close
End If
Next i
End Sub


"Jean-Yves" wrote:

HI,

Keep shift key pressed, menu File/Close all
or
Private Sub Workbook_BeforeClose(Cancel As Boolean)

dim wb as workbook
for each wb in workbooks
if wb.name < thisworkbook.namen then wb.close False 'close without save
next
End Sub

Put this in the Thisworkbook module
Regards
JY

"colt" wrote in message
...
how can i close all open office files as i close current active workbook?






All times are GMT +1. The time now is 04:36 AM.

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