Link to home
Start Free TrialLog in
Avatar of Rothbard
RothbardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Building a DLL for use in Excel

Suppose I have a function written in C++, say

double GenerateRandomNumber(double seed)

I want to compile it as a DLL and attach it to an Excel spreadsheet, so I can use it like an ordinary VBA function. My questions:

1. How do I change the settings in Visual Studio so that the code gets compiled as a DLL?
2. How do I use the DLL in Excel?
Avatar of jkr
jkr
Flag of Germany image

Check out http://support.microsoft.com/kb/178474 ("How To Build an Add-in (XLL) for Excel Using Visual C++ ")
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rothbard

ASKER

Is there any way of doing this without having to buy the book "Microsoft Excel 97 Developer's Kit"?
By the way, I tried to load the XLL file provided on the Code Project website, but it didn't work in my copy of Excel 2003. I get the error "Interp32.dll is not a valid add-in".
Is there a way of calling a DLL from Excel without actually making an Add-In out of it?
I forgot to add that I don't need to use the DLL in an Excel sheet, it's enough to be able to use it in VBA.
>>Is there a way of calling a DLL from Excel without actually making an Add-In
>>out of it?

I strongly doubt that, even from VBA. Except maybe if you can call COM objects from VBA, them that would be an option.
So if I make it a COM DLL I should be able to call it from VBA? How can I do that?
WeGood question. I don't even know VBA well enough to know if that is possible at all...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How do I set the reference? I don't have a project by the way, only a module in an Excel spreadsheet.
Every workbook contains/is a project. You set a reference via the Tools->References option of the menu. You will need to browse to your dll.
Rory