Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find the order of open windows? 1

Status
Not open for further replies.

duGly

Technical User
Nov 13, 2006
52
US
OK, my question's a bit hard to explain, so please bear with me.

I am using VBA in Word 2003. In my DocumentBeforeClose event, I want to reconfigure my menu based on which document will become active.

To do so, I need to find the order of open windows (documents). If I use Application.Documents or Application.Windows, I get a collection of open documents in the order in which they were opened. However, I want the order in which they were last activated.

For example, say I have four documents open and I activate them in the following order:
• Doc2
• Doc4
• Doc3
• Doc1

If I close Doc1 (the active document), Doc3 becomes the active document (regardless of its order in the Application.Documents or Application.Windows collections). How do I programmatically find out which document is next in this order (ie. which document will become active when my active document is closed)?
 



Hi,

There is a WindowSelectionChange Event. You could capture the order of these in an array.

Skip,

[glasses] [red][/red]
[tongue]
 
Have you tried to play with the Previous property of the Window object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, PH. I tried the Previous property already. Unfortunately, it just returns the previous item in the collection regardless of the order of selection.

Skip, Thanks for pointing me to the WindowSelectionChange event. That will work great. I already have a class module with a DocumentChange event, so I think I'll build the array there.
 



I'd take a look at ALL the events that are available to see which one(s) might be useful.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top