Multiple windows mayhem

nigelandrewfoster

Well-known Member
Joined
May 27, 2009
Messages
747
If my workbook has 3 windows, called A,B and C (their names will vary) and Windows(1) is always the active window (let's say it's A at present), then how do I know if Windows(2) corresponds to B or C? Had a right load of fun with it this afternoon. Then I add a new window. What's the computer going to call that, and what index number will that one be referred to by? It seems to be making it up as it goes along. :-)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi

It's good practice to name the windows as you create them, or else it can get confusing.

For ex., in a new workbook execute:

Code:
Sub Macro1()
 
ActiveWindow.Caption = "A"
ActiveWindow.NewWindow.Caption = "B"
ActiveWindow.NewWindow.Caption = "C"
Windows("A").Activate
End Sub

The index represents the order of activation (most recent first). So, after running this code you'd get (A,1), (C,2), (B,3).

A better way is to assign the windows to variables. This way you can easily refer to them using the variables.

Code:
Sub Macro1()
Dim winA As Window, winB As Window, winC As Window
 
Set winA = ActiveWindow
Set winB = winA.NewWindow
Set winC = winA.NewWindow
 
' for ex., change caption of winB and activate winA
winB.Caption = "B"
winA.Activate
End Sub
 
Upvote 0
Thanks for that. Very helpful indeed. One final question: Your method of declaring and defining the windows at the beginning is what I want to do. Sometimes, though, I only want one of the windows visible, I had been using the .CLOSE method, but that means redefining it again, checking how many are open, etc. Can unused windows be temprarily hidden in some way?
 
Upvote 0

Forum statistics

Threads
1,226,217
Messages
6,189,687
Members
453,563
Latest member
Aswathimsanil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top