MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Window Name - Close


Posted by Thomas Venn on September 01, 2000 4:11 PM

Hello,

This is my current code:
Windows("Book7").Activate
Application.Goto Reference:="R1C1"
ActiveWorkbook.Close
Application.Goto Reference:="R1C1"
Windows("Book6").Activate
Application.Goto Reference:="R1C1"
ActiveWorkbook.Close
Windows("Book5").Activate
Application.Goto Reference:="R1C1"
ActiveWorkbook.Close

"Book7" is window #2 of 50 windows I have open. What I want to do is go to window #2, each and every time, so that when I go there, I am able to close that certain workbook, and have the next workbook be window #2, and I want to repeat this process. Repeating the process is the reason why i want to use a generic name instead of using a specific window name.

In the above example, when I close "Book7", then "Book6" becomes window #2, and when I close "Book6", then "Book5" becomes window #2, and so on...

Thank you in advance.

Thomas Venn


Posted by Celia on September 01, 0100 9:17 PM

Thomas
See if the followimg does what you need :-

Dim wb As Workbook
For Each wb In Workbooks
If wb.Name <> ActiveWorkbook.Name Then
wb.Application.Goto Reference:="R1C1"
wb.Close savechanges:=True
End If
Next

Celia