Excel 2007 does not return shape data using XLL xlfGetDocument command

Summary

Microsoft Excel XLL add-ins using the xlfGetDocument command with the command type 42 to return a matrix of shapes (objects, images, controls) on the active sheet may encounter problems in Excel 2007, because the command fails to return any such information to the add-in.   The caller receives no error, but gets back an empty XLOPER, as if the sheet contains no shapes, even if it does.

Cause

The problem occurs because of a design change made in how Excel handles shapes.  A new shape object type is used for objects, images, and controls in Office 2007.  The code called by the xlfGetDocument command is using an older routine that does not anticipate the new shape types, and therefore fails to find the shapes on the sheet.  It returns successfully under the assumption that the sheet has no shapes.

Status

This is a confirmed bug in Excel 2007, and is being investigated for a future fix in SP2 and/or Office 14.

More Information

When used in an XLL, the following code snippet can reproduce the problem. You need a sheet with an image or ActiveX control on it, and then call an XLL function which does the following:

Excel(xlfGetDocument, &xObjects, 1, TempNum(42));

if ( xObjects.xltype & xltypeMulti )

{

  count = xObjects.val.array.rows * xObjects.val.array.columns;

  // You got array of data and can determine shape count on sheet.

}

else

{

  // You got back no data; Excel says there is no shapes on this sheet!

}

Running the code from Excel 2002 or Excel 2003 will return the lxtypeMulti XLOPER with the object array data, but will return an empty value in Excel 2007 for the same worksheet.