anandha123
New Member
- Joined
- May 6, 2011
- Messages
- 3
Hi there,
I have installed Excel 2010 in my machine. I have Excel Interop module to launch Excel from my application.
when i launch Excel spreadsheet form my application, i see in the formula cells which refers method of add-in "myaddin.xla" appears like,
#NAME and actually the content of the cell is ='C:\MyApplication\Addin\myaddin.xla'!MYFUNC(B7).
If i remove the full path of the addin and make it like 'myaddin.xla'!MYFUNC(B7), Its working fine.
My workbook is having plenty of references and i cannot change it manually at every cell.
So, to avoid that I have written the following code using Workbook.ChangeLink method to replace C:\MyApplication\Addin\myaddin.xla to myaddin.xla,
But after executing the ChangeLink method for the first time it throws exception and it had changed only in the current active worksheet of the workbook.
Other worksheets of the workbook are untouched.
Here is my code,
/* *************************************/
.....
.....
unprotect_sheets(wbk); // In this method's implementation am looping through each worksheet of the workbook and unprotect UserInterfaceOnly
variant_t Links = wbk->LinkSources();
char name_text[256];
if (Links.vt != VT_EMPTY)
{
SAFEARRAY *arr;
unsigned int nDim;
long ubound;
arr = Links.parray;
nDim = SafeArrayGetDim(arr);
if (nDim == 1)
{
h = SafeArrayGetUBound(arr, 1, &ubound);
if (SUCCEEDED(h))
{
for (long ix = 1;ix <= ubound; ix++)
{
variant_t name;
h = SafeArrayGetElement(arr,&ix,&name);
if (SUCCEEDED(h))
{
bstr_t b_name = name;
strcpy(name_text,b_name);
if (strstr(name_text,"myaddin.xla") != NULL)
{
try
{
// Code which throws exception
wbk->ChangeLink(b_name,"myaddin.xla",Excel::xlLinkTypeExcelLinks);
}
catch (_com_error &e)
{
//Failure...
}
}
}
}
}
}
}
/****************************************/
The exception what am getting has error code -2146827284. But couldnt get any information from this.
Can anyone help me to solve this problem.. Am struct on this issue for long time..!
Thanks in advance,
Anandh
I have installed Excel 2010 in my machine. I have Excel Interop module to launch Excel from my application.
when i launch Excel spreadsheet form my application, i see in the formula cells which refers method of add-in "myaddin.xla" appears like,
#NAME and actually the content of the cell is ='C:\MyApplication\Addin\myaddin.xla'!MYFUNC(B7).
If i remove the full path of the addin and make it like 'myaddin.xla'!MYFUNC(B7), Its working fine.
My workbook is having plenty of references and i cannot change it manually at every cell.
So, to avoid that I have written the following code using Workbook.ChangeLink method to replace C:\MyApplication\Addin\myaddin.xla to myaddin.xla,
But after executing the ChangeLink method for the first time it throws exception and it had changed only in the current active worksheet of the workbook.
Other worksheets of the workbook are untouched.
Here is my code,
/* *************************************/
.....
.....
unprotect_sheets(wbk); // In this method's implementation am looping through each worksheet of the workbook and unprotect UserInterfaceOnly
variant_t Links = wbk->LinkSources();
char name_text[256];
if (Links.vt != VT_EMPTY)
{
SAFEARRAY *arr;
unsigned int nDim;
long ubound;
arr = Links.parray;
nDim = SafeArrayGetDim(arr);
if (nDim == 1)
{
h = SafeArrayGetUBound(arr, 1, &ubound);
if (SUCCEEDED(h))
{
for (long ix = 1;ix <= ubound; ix++)
{
variant_t name;
h = SafeArrayGetElement(arr,&ix,&name);
if (SUCCEEDED(h))
{
bstr_t b_name = name;
strcpy(name_text,b_name);
if (strstr(name_text,"myaddin.xla") != NULL)
{
try
{
// Code which throws exception
wbk->ChangeLink(b_name,"myaddin.xla",Excel::xlLinkTypeExcelLinks);
}
catch (_com_error &e)
{
//Failure...
}
}
}
}
}
}
}
/****************************************/
The exception what am getting has error code -2146827284. But couldnt get any information from this.
Can anyone help me to solve this problem.. Am struct on this issue for long time..!
Thanks in advance,
Anandh