Last modified: March 18, 2009

Applies to: Excel 2010 | Office 2010 | VBA | Visual Studio

Finds the sheet ID of a named sheet in order to construct external references.

Excel12(xlSheetId, LPXLOPER12 pxRes, 1, LPXLOPER12 pxSheetName);

pxSheetName (xltypeStr)

(Optional). The name of the book and sheet you want to find out about. If omitted, the xlSheetId function returns the sheet ID of the active (front) sheet.

Returns the sheet ID in pxRes->val.mref.idSheet.

Note Note

The pxRes->val.mref.lpmref array pointer is set to NULL after this call so that there is no need to call xlFree to release the memory that this type normally contains, although it is completely safe to do so.

The workbook containing the specified sheet must be open to use this function. There is no way to construct a reference to an unopened workbook from a DLL. For more information about using xlSheetId to construct references, see Memory Management in Excel for examples of xltypeRef construction.


short WINAPI xlSheetIdExample(void)
   XLOPER12 xSheetName, xRes;

   xSheetName.xltype = xltypeStr;
   xSheetName.val.str = L"\022[BOOK1.XLSX]Sheet1";
   Excel12(xlSheetId, &xRes, 1, (LPXLOPER12)&xSheetName);
   Excel12f(xlcAlert, 0, 1, TempNum12(xRes.val.mref.idSheet));
   Excel12(xlFree, 0, 1, (LPXLOPER12)&xRes);
   return 1;