View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
mcambrose mcambrose is offline
external usenet poster
 
Posts: 27
Default refer to active window when more than one window open for a file

I found that if I select a cell in the window that I want to operate on, I
can use the command workbooks("mybook"). windows(1).activate (assuming
"mybook" is the name for my workbook") to come back to that same window if I
don't change the selected window in my code. I thought that the index value
would match the order in which the windows were created, but it seems that
the index changes each time a window is selected. For example, if I issue the
command workbooks("mybook"). windows(2).activate, it will toggle to the other
window. If I run the command again it will toggle back to the previous
window. Thus if two windows are open for a workbook, the active window is
window 1 and the other window is window 2. I don't know or care what happens
if more than two windows are open. I just wanted to follow up in case somone
else ran into this question/issue.

"mcambrose" wrote:

How do I refer to a specific window when I have a file with multiple windows
open. I originally wrote a macro to operate on a workbook with only one
window open. I used the workbooks("mybook").activate, but now that I have
more than one window open, it always selects the first window. If i am in the
second window when I run the macro, it puts the information in the active
cell in the first window of the workbook. How to I specifically refer to
window where the cursor is. Do I use some type of activewindow command? do i
create an object and set it equal to the current window? Thanks.