VBA : Closing workbooks except.....

  • Hi,


    I need a macro that will close all the workbooks except the one that is "activated". I know the macro


    workbooks.close


    but it closes all the workbooks.


    Cheers


    Jay

  • You can use for ... next loop for this


    For i = 1 To Workbooks.Count
    If (Workbooks(i).Name <> ActiveWorkbook.Name) Then
    Workbooks(i).Close
    End If
    Next i


    Regards,
    greg

  • From http://www.excel-center.com/mailing/032198h.htm


    Code
    'Place the code below into the standard module
    Sub Tally()
    Dim WB As Workbook
        For Each WB In Workbooks
            If WB.Name <> ThisWorkbook.Name Then
                WB.Close savechanges:=False
            End If
        Next WB
    End Sub


    HTH

    &lt;a href="http://www.mrexcel.com/relayforlife.shtml" target="new"&gt;&lt;img src="http://www.myimgs.com/data/vonpookie/anne_relay.gif"&gt;&lt;/a&gt;

  • Hi,


    Similar to Iridium's post:

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!