Error Using WORKBOOK.ADD() without First Argument

Last reviewed: July 16, 1997
Article ID: Q84172

The information in this article applies to:
  • Microsoft Excel for Windows, versions 4.0, 5.0

SYMPTOMS

Microsoft Excel requires a worksheet name for the first argument in the WORKBOOK.ADD() function. If you use this macro function without the first argument, you receive a macro error when you run the macro that contains this function.

In Microsoft Excel version 5.0, if you use this function in a Microsoft Excel version 4.0 macro sheet without the first argument, you receive a general protection (GP) fault.

CAUSE

You can use the WORKBOOK.ADD function to add one or more documents to a workbook in Microsoft Excel version 4.0. If the worksheet argument is left out in most functions, the active sheet is assumed. This is not the case for the WORKBOOK.ADD function.

The WORKBOOK.ADD function requires a first argument and will halt on a macro error if no argument is given. This also applies to the WORKBOOK.COPY() and WORKBOOK.MOVE() functions.

WORKAROUNDS

Microsoft Excel version 5.0

To avoid receiving a GP fault in Microsoft Excel version 5.0, use either of the following methods:

Method 1: Use the WORKBOOK.MOVE function instead of the WORKBOOK.ADD

          function. You  can use the WORKBOOK.MOVE function without the
          first argument to move  the active sheet to the specified
          workbook, unless the active sheet is  the only sheet contained in
          the workbook.

Method 2: Use the Move method of the Sheets object to move the active sheet
          to  another workbook. The following example moves the active
          sheet to BOOK1:

             ActiveSheet.Move Workbooks("Book1").Sheets(1)

          Note that the sheet is inserted before Sheet1 in BOOK1.


Microsoft Excel version 4.0

To avoid receiving a macro error in Microsoft Excel version 4.0, use GET.DOCUMENT(1) for the first argument. This returns the name of the active sheet.

REFERENCES

"Function Reference," version 4.0, page 461


Additional query words: 4.00 4.0 5.00 work book gpf
Keywords : kbmacro kbprg
Version : 4.00 5.00
Platform : 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: July 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.