Remove full addin path from Formula

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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Is that actually the correct path for your addin?
 
Upvote 0
To be honest I doubt you will get specific code help here as few Excel people really use C++ in my experience, but I am intrigued by this comment in your code: "unprotect UserInterfaceOnly" since you can't do that - you can only protect with Userinterfaceonly and that's not particularly reliable in my experience.
I am surprised that you only get the path changed in one sheet though as the workbook Changelink method is not sheet specific.
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top