Microsoft KB Archive/110624

From BetaArchive Wiki

Microsoft Knowledge Base

XL: Problems When Two Windows Share the Same Title

Last reviewed: March 27, 1997
Article ID: Q110624

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:

  1. Create a new workbook ("Book1") that contains a Visual Basic module and a worksheet.
  2. In cell A1 in the worksheet, enter "Book1" (without the quotation marks).
  3. Enter the following subroutine into the module:

    '-------------------------------------------------------------------

          Sub ChangeCaption()
             ActiveWindow.Caption = "Test"       'changes the window's caption
          End Sub
          '-------------------------------------------------------------------
    
  4. Create another new workbook ("Book2") that contains a worksheet.
  5. In cell A1 in the worksheet, enter "Book2".
  6. While Book2 is active, choose Macro from the Tools menu.
  7. Select "Book1!ChangeCaption" from the list of macros. Choose Run.

The caption for Book2 will change to "Test."

  1. From the Window menu, choose Book1.
  2. While Book1 is active, choose Macro from the Tools menu.
  3. From the list of macros, select "ChangeCaption." Choose Run.

The caption for Book1 will also change to "Test."

  1. From the Window menu, choose Arrange. Select the Tiled option and

        choose OK.
  2. 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:

  1. Create a new workbook ("Book3") that contains a Visual Basic module.
  2. Enter the following subroutine into the module:

       '----------------------------------------------------------------------
       Sub Activator()
          Windows("Test").Activate              'activate the window "Test"
       End Sub
       '----------------------------------------------------------------------
    
  3. 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:

  1. Activate Test (Book2).
  2. From the Window menu, choose Hide.

The Test(Book2) window should now be hidden.

  1. From the Window menu, choose Unhide.
  2. Select "Test" from the list of hidden workbooks. Choose OK.

The Test(Book2) window becomes visible.

  1. Activate Test(Book1).
  2. From the Window menu, choose Hide.

The Test(Book1) window should now be hidden.

  1. From the Window menu, choose Unhide.
  2. 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).


KBCategory: kbusage

KBSubcategory:

Additional reference words: 5.00 7.00
Keywords : kbusage
Version : 5.00 5.00c 7.00 7.00a | 5.00 5.0
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 27, 1997
©1997 Microsoft Corporation. All rights reserved. Legal Notices.