Friday, July 31, 2009

How do you OLE link visual c++ into excel?

I would like to compile C++ in excel, and was told I would have to OLE link both programs. THis is all fine and dandy, but I have absolutely no idea on how to do this.

How do you OLE link visual c++ into excel?
Let's try again. If your plan is to use the facilities of Excel in a c++ program you write, this is very possible. If your plan is to use some c++ functions you write and call them in Excel, this is also very possible. It's just not easy to tell from your question which of these you want to do.





If you want to call c++ functions in Excel, you must create a DLL in c++ (keeping in mind that the function you want to call must have 'c' linkage--that is, no name mangling else you'll not be able to find them in Excel) with the desired functions being exportable. You can then write some vba code that calls the DLL functions.





If you want to, say, open Excel in your c++ code, fill some cells in a sheet, save the sheet, this is easy. Mind you, it's easier to do it with languages like VB or perl. But you can do it with c++. One pretty simple way is to write some VB and convert it to c++. See http://support.microsoft.com/kb/216388 for a simple way to do this. Google other terms for sample c++ code to invoke Excel via COM. BTW, Excel can act as an 'automation server' or 'COM server', which is indeed related to OLE.
Reply:Maybe it's your question that's unclear. We simply interpret your illogical statements in different ways and trying to GUESS what you mean. Though by your comment, sounds like you don't know what you want either. Report It

Reply:Then I guess the "best answer" you chose didn't answer you either. "Compile Excel in C++ compiler" is a non-starter to begin with. Report It

Reply:Your request makes absolutely NO SENSE, and whoever gave you that answer was confused.





OLE is for embedding documents, like an Excel chart and an Access table into Word document. It's not for mix-and-match applications.





Why in heavens would you want to compile C++ in Excel any way?





And C++ is a language. All you'd end up embedding, even if that were possible, is the IDE (i.e. the editor), not the language / compiled program.


No comments:

Post a Comment