Microsoft KB Archive/86196

{|
 * width="100%"|

Excel: GET.WORKBOOK Returns Error

 * }

-

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 &quot;Microsoft Excel Function Reference&quot; states that the optional argument to GET.WORKBOOK, &quot;NAME_TEXT,&quot; 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(&quot;]&quot;,Get.Document(1)) A2: =MID(GET.DOCUMENT(1),count+1,LEN(GET.DOCUMENT(1))-count)

where &quot;count&quot; is a variable that contains the position of the &quot;]&quot; 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.