The workbooks collections object can be used to reference all open workbooks
Using this object to close all open workbooks is very easy.
Code:Sub ClsOpnWbs() ' http://www.excelfox.com/forum/showthread.php/2422-Close-the-open-excel-file Dim AnyWb As Workbook For Each AnyWb In Workbooks If AnyWb.Name <> ThisWorkbook.Name Then 'AnyWb.Close Savechanges = True ' 'True:- To save any changes AnyWb.Close Savechanges = False ' ' False:- File is not saved. No changes will be saved. Else ' case AnyWb is this workbook ' Do nothing on this Loop End If Next AnyWb End Sub




Reply With Quote

Bookmarks