ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can't add a reference to specified file (https://www.excelbanter.com/excel-programming/296376-cant-add-reference-specified-file.html)

Bura Tino

Can't add a reference to specified file
 
Hi,

About a year ago I wrote C++ excel add-in, which provides a few worksheet
function which I still use quite frequently and successfully. Now I want to
use the same function in VBA. From what I understand, I need to add a
reference to the add-in first, but when I pick my xll from the browse menu,
I get the "Can't add a reference to specified file" error. Something is
probably screwed inside my xll. Can you recommend what I should look at.

Many thanks!

Bura.

PS: The function that I want to use is one that takes a URL and returns the
contents of that resource. In particular, I'm running a few servers and I
need for my VBA code to find the live ones. So I request an
http://serverN/AreYouAlive.jsp, and the server replies "yes" and my function
passes it through, or the request time outs and my function returns "no". In
VBA I would like to be able to say if getURL(http://serverN/AreYouAlive.jsp)
= "yes"... Perhaps someone could suggest an alternative way of doing this
and then the primary question is this post will become moot. Thanks again.



Tom Ogilvy

Can't add a reference to specified file
 
If it is a xll/dll, I believe you would declare it just like a windows API.
(rather than set a reference to it).

This article gives an example of making a DLL and calling it from VB (should
be the same for VBA).

http://support.microsoft.com/default...46&Product=vbb

Include the path if it isn't in the system directory I believe.
HOWTO: Pass Optional Parameters to a C DLL Function from VB

--
Regards,
Tom Ogilvy


"Bura Tino" wrote in message
...
Hi,

About a year ago I wrote C++ excel add-in, which provides a few worksheet
function which I still use quite frequently and successfully. Now I want

to
use the same function in VBA. From what I understand, I need to add a
reference to the add-in first, but when I pick my xll from the browse

menu,
I get the "Can't add a reference to specified file" error. Something is
probably screwed inside my xll. Can you recommend what I should look at.

Many thanks!

Bura.

PS: The function that I want to use is one that takes a URL and returns

the
contents of that resource. In particular, I'm running a few servers and I
need for my VBA code to find the live ones. So I request an
http://serverN/AreYouAlive.jsp, and the server replies "yes" and my

function
passes it through, or the request time outs and my function returns "no".

In
VBA I would like to be able to say if

getURL(http://serverN/AreYouAlive.jsp)
= "yes"... Perhaps someone could suggest an alternative way of doing this
and then the primary question is this post will become moot. Thanks again.





Bura Tino

Can't add a reference to specified file
 

"Tom Ogilvy" wrote in message
...
If it is a xll/dll, I believe you would declare it just like a windows

API.
(rather than set a reference to it).

This article gives an example of making a DLL and calling it from VB

(should
be the same for VBA).

http://support.microsoft.com/default...46&Product=vbb

Include the path if it isn't in the system directory I believe.
HOWTO: Pass Optional Parameters to a C DLL Function from VB

--


Thanks Tom. Couldn't quite get it to work. So I'll post more info and
perhaps you or someone else could suggest the precise declaration to use.

1. Function Registering Table:
static LPSTR func[][14] = {
{ " getURL" , " RP" , " getURL" , " URL String" , " 1", " Transcend", " ", "
", " Non Volatile NOW()" , " This dummy dependency argument is unused inside
the funtion", " ", " ", " ", " "},
};

2. The DEF file snippet:
getURL


3. And here's the very ugly getURL function (but it works)

LPXLOPER __stdcall getURL(LPXLOPER inX) {
static XLOPER xRes;
Excel4(xlfNow, &xRes, 0); // Returns an xltypeNum;
xRes.xltype = xltypeStr;
xRes.val.str = (PUCHAR) " Input not a URL";
if (inX-xltype == xltypeStr) {
string *a = new string(" " + utilityURLToString(toStr(inX-val.str))); //
a function that uses the curl package compiled into the addin.
xRes.val.str = (PUCHAR) a-c_str();
xRes.val.str[0] = a-length() - 1;
xRes.xltype = xltypeStr;
}
return &xRes;
}


This works beautifully in worksheets and I want to have the function getURL
available in VBA!


Very many thanks!!! I would be exstatic if I can get this to work and I
think this will be useful to others as well!

(Hopeful) Bura





All times are GMT +1. The time now is 03:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com