Macro to Open or Activate a Sheet in Microsoft Excel

Last reviewed: September 2, 1997
Article ID: Q74694

The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 4.0a
  • Microsoft Excel for OS/2, versions 2.2, 2.21, and 3.0

SUMMARY

When you activate a worksheet from a macro, the worksheet must first be opened. You will receive a "Macro Error at Cell: xx" if the sheet is closed.

The following macro will activate SHEET1.XLS if it is already open, or it will open and activate SHEET1.XLS if the sheet is closed.

MORE INFORMATION

Microsoft provides macro examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This macro is provided 'as is' and Microsoft does not guarantee that the following code can be used in all situations. Microsoft does not support modifications of the code to suit customer requirements for a particular purpose.

  1. Enter the following into a macro sheet:

          A1: ActivateSheet
          A2: =ERROR(FALSE)
          A3: =IF(ISERROR(ACTIVATE("SHEET1.XLS")),OPEN("SHEET1.XLS"))
          A4: =ERROR(TRUE)
          A5: =RETURN()
    

  2. Define the macro by selecting cell A1. Click Define Name on the Formula menu.

    The name will appear in the Name box.

  3. Select Command in the Macro section at the bottom of the dialog box and click OK.

For information about how to do this with a Visual Basic for Applications procedure, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q135390
   TITLE     : XL: VB for Apps Procedure to Open or Activate a Workbook

REFERENCES

"Microsoft Excel Function Reference," version 4.0, pages 135, 225, and 24 "Microsoft Excel Function Reference," version 3.0, pages 68, 125, and 135 "Microsoft Excel Functions and Macros," version 2.1, pages 57, 65-66, 274


Additional query words: 2.0 2.00 2.01 2.1 2.10 2.2 2.20 2.21 3.0 3.00 4.0
4.00
Keywords : kbmacro kbprg PgmHowTo PgmOthr
Version : 2.x 3.00 4.00 4.00a | 2.20 2.21
Platform : OS/2 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: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.