Macro switch between windows question

  • Thread starter Thread starter punter
  • Start date Start date
P

punter

Hi,

I have a macro that is flipping between two windows. I recorded it an
I'm running into an error. The sheet I was playing around with an
recorded it on was called Book1. The macro will be run on sheets wit
different names. The debugger is highlighting this line:

Windows("Book1.xls").Activate

How do I make windows go the other open workbook no matter what th
name is?

Thanks

Eddi
 
Hi

I guess the problem is that new workbooks won't always be calle
"book1".

You could save the new workbook as soon as it's opened in the macro
thereby giving it a set name and changin the macro to reflect tha
name.

Alternatively you could prompt the user to tell the macro what th
workbook name is and then refer to that.

Hope this helps

Coli
 
This should work if you have only two workbooks open:
For j=1 to workbooks.count
if workbooks(j).name<>activeworkbook.name then
workbooks(j).activate
exit for
end if
next j

James
 
Back
Top