After finding the following page
http://msdn.microsoft.com/en-us/library/office/bb211879%28v=office.12%29.aspx[
^]
I came up with the solution below:
int CExcelOLE_Func::FindName(const char * pszName, CName * pName)
{
...
...
if (m_pWorkbook != NULL)
{
if ((lpDisp = m_pWorkbook->get_Names()) != NULL)
{
pNames->AttachDispatch(lpDisp);
i = 1;
while ((i <= pNames->get_Count()) && (nRetVal == 0))
{
if ((lpDisp = pNames->Item(COleVariant((short)i), varOption, varOption)) != NULL)
{
pLocalName->AttachDispatch(lpDisp);
if (pLocalName->get_Name() == pszName)
{
nRetVal = 1;
}
}
i++;
}
}
}
....
....
return nRetVal;
}
I made a error previously by indexing the CNames collection from base 0 instead of base 1 (an easy mistake if come from a C/C++ background!). I'm interested in named ranges and I been able to obtain the starting row associated with the range using:
if (pExcelFunc->FindName("DR_ClosureTracking", pName))
{
CRange range;
if ((lpDisp = pName->get_RefersToRange()) != NULL)
{
range.AttachDispatch(lpDisp);
nBaseRow = range.get_Row();
}
}