Excel: GET.WORKBOOK Returns Error

Last reviewed: February 22, 1995
Article ID: Q86196
The information in this article applies to:
  • Microsoft Excel for Windows, version 4.0
  • Microsoft Excel for the Macintosh, version 4.0

SUMMARY

The GET.WORKBOOK function will return #N/A if the name of the workbook is not specified, and if the Workbook Contents Window is not the active document when the macro executes this function.

MORE INFORMATION

Page 209 of the "Microsoft Excel Function Reference" states that the optional argument to GET.WORKBOOK, "NAME_TEXT," is the name of an open workbook, and if omitted, is assumed to be the active workbook.

This documentation is incomplete. It does not state that the Workbook Contents Window of the active workbook must be the active window for GET.WORKBOOK to return the correct values. If any other window of the workbook is active, and the second argument is omitted, GET.WORKBOOK will return #N/A.

WORKAROUND

Use the Get.Document() function when trying to return the name of the active document in a workbook. If you use the following syntax on a macro sheet:

   A1:  =Get.Document(1)

the name of the active document in the workbook (including the name of the workbook) will be returned to cell A1 on the macro sheet.

If you would like to just extract the name of the active worksheet in the workbook (without the workbook name) use the following syntax on a macro sheet:

   A1:  count=Search("]",Get.Document(1))
   A2:  =MID(GET.DOCUMENT(1),count+1,LEN(GET.DOCUMENT(1))-count)

where "count" is a variable that contains the position of the "]" character in the string returned by the Get.Document(1) function call. The name of just the active document in the workbook should be returned to cell A2 in the macro sheet.

REFERENCES

"Microsoft Excel Function Reference," version 4.0, pages 4, 209, 460

"Microsoft Excel User's Guide 1," version 4.0, page 69


KBCategory: kbdocerr
KBSubcategory:

Additional reference words: 4.0 4.00


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: February 22, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.