Rothbard
asked on
Building a DLL for use in Excel
Suppose I have a function written in C++, say
double GenerateRandomNumber(doubl e 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?
double GenerateRandomNumber(doubl
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?
Check out http://support.microsoft.com/kb/178474 ("How To Build an Add-in (XLL) for Excel Using Visual C++ ")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there any way of doing this without having to buy the book "Microsoft Excel 97 Developer's Kit"?
ASKER
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".
ASKER
Is there a way of calling a DLL from Excel without actually making an Add-In out of it?
ASKER
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.
>>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.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Rory