5.00 5.00c 7.00 7.00a | 5.00 5.00a
WINDOWS | MACINTOSH
kbusage
The information in this article applies to:
- Microsoft Excel for Windows, versions 5.0, 5.0c
- Microsoft Excel for Windows 95, versions 7.0, 7.0a
- Microsoft Excel for the Macintosh, versions 5.0, 5.0a
SUMMARY
In Microsoft Excel, if two windows share the same caption, you may
experience difficulties when you attempt to do either of the following:
- Activate one of the windows with a Visual Basic Activate method
-or-
- Unhide a hidden window that has the same title as a visible window
NOTE: This problem does not occur in Microsoft Excel version 7.0.
MORE INFORMATION
The caption of a window is the text that appears in the title bar of the
window. For example, if you create a new workbook, its caption will
probably be Bookn (or some variation of Bookn), where n is the number of
open books. You can change the caption of the active window by using the
following Visual Basic command
ActiveWindow.Caption = "Test"
where Test is the desired caption.
When Microsoft Excel encounters a situation involving two or more windows
that share the same caption, the windows are considered in reverse order of
creation: that is, the more recently created windows are given priority
over windows that were created earlier.
This prioritization may cause problems when you are working with multiple
windows (particularly if you are trying to activate or unhide windows).
Steps to Reproduce Behavior
To create two windows that share the same caption, do the following:
- Create a new workbook ("Book1") that contains a Visual Basic
module and a worksheet.
- In cell A1 in the worksheet, enter "Book1" (without the quotation
marks).
- Enter the following subroutine into the module:
'-------------------------------------------------------------------
Sub ChangeCaption()
ActiveWindow.Caption = "Test" 'changes the window's caption
End Sub
'-------------------------------------------------------------------
- Create another new workbook ("Book2") that contains a worksheet.
- In cell A1 in the worksheet, enter "Book2".
- While Book2 is active, choose Macro from the Tools menu.
- Select "Book1!ChangeCaption" from the list of macros. Choose Run.
The caption for Book2 will change to "Test."
- From the Window menu, choose Book1.
- While Book1 is active, choose Macro from the Tools menu.
- From the list of macros, select "ChangeCaption." Choose Run.
The caption for Book1 will also change to "Test."
- From the Window menu, choose Arrange. Select the Tiled option and
choose OK.
- In each workbook, activate the worksheet. This allows you to see cell
A1 for each sheet, this cell contains the original name of each
workbook.
You should now have two tiled windows whose captions are both "Test."
At this point, you may want to save the workbooks as BOOK1.XLS and
BOOK2.XLS so that you can easily reproduce this situation again as
necessary.
Examples
The following examples illustrate two of the problems you may encounter
when you are working with two or more windows share the same caption.
Problem 1:
To get a better understanding of the problems that arise when you activate
a window when two windows share the same caption, follow the steps below:
- Create a new workbook ("Book3") that contains a Visual Basic module.
- Enter the following subroutine into the module:
'----------------------------------------------------------------------
Sub Activator()
Windows("Test").Activate 'activate the window "Test"
End Sub
'----------------------------------------------------------------------
- From the Window menu, choose Arrange. Select the Tiled option
and then choose OK.
All three windows Book3, Test(Book1), and Test(Book2) should be tiled.
If you run the Activator subroutine, the window that becomes active
varies, depending on which window is active when you run it:
Active When Subroutine Starts Active When Subroutine Ends
-----------------------------------------------------------
Test(Book1) Test(Book1)
Test(Book2) Test(Book2)
Book3 Test(Book2)
If you Activate a window, the Activate method checks for the window in the
following order:
- If the active window has the same caption as the window that is to
be activated, keep the active window active.
- If the captions are different, activate the most recently created window
that has the correct caption.
This second item explains why Test(Book2) becomes active when the
subroutine is run from Book3. Because the caption of Book3 is not "Test,"
the subroutine activates the most recently created window whose caption is
"Test" [in this case, Test(Book2)].
For this reason, if the window Test(Book1) is active, you may find it
impossible to activate Test(Book2), or vice versa. In some cases, you
may find it possible to activate another window that has the same
caption by first activating a third window and then activating the
desired window.
Problem 2:
To get a better understanding of the problems that arise when you unhide a
Window that shares the same caption as a visible window, follow the steps
below:
- Activate Test (Book2).
- From the Window menu, choose Hide.
The Test(Book2) window should now be hidden.
- From the Window menu, choose Unhide.
- Select "Test" from the list of hidden workbooks. Choose OK.
The Test(Book2) window becomes visible.
- Activate Test(Book1).
- From the Window menu, choose Hide.
The Test(Book1) window should now be hidden.
- From the Window menu, choose Unhide.
- Select "Test" from the list of hidden workbooks. Choose OK.
The Test(Book1) window remains hidden. This window remains hidden because
of the way in which Microsoft Excel handles requests to unhide windows.
When you request for Microsoft Excel to unhide a window, it searches
through the windows in reverse order of creation: that is, more recently
created windows are unhidden before windows that were created earlier.
In the first case, hiding and unhiding Test(Book2), when you request
Microsoft Excel to unhide Test, the newest "Test" is Test(Book2); because
it is hidden, Microsoft Excel unhides the window.
In the second case, hiding and unhiding Test(Book1), when you request
for Microsoft Excel to unhide Test, the newest "Test" is still
Test(Book2); because that window is already visible, Microsoft Excel
assumes that no further processing of the request is necessary, and
Test(Book1) remains hidden.
To unhide Test(Book1), you must first close Test(Book2) or change the
caption of the Test(Book2).