Entete, menu et pied de page

F o r e v e r


Set Interoperability between C++ (visual Studio) and VBA Excel

This little paper will help people to capitalize on the power of C++ and Excel
Ergonomics. It may help many people in financial industry to model faster.

What to do In Visual Studio ?

--- Open Visual Studio (for instance 2008) and select New project
--- Choose MFC DLL like in the following picture

--- Enter the project name (e.g Mydll.dll) and click OK
--- In the following application wizard select next

--- -In the following wizard select « Regular dll using shared MFC » and select the check button « automation »

--- Click Next
--- Build the project before continuing; the build must be a success before going on
--- Add a Class by Clicking right on the solution name and choosing ADD+Class
--- In the Class wizard, choose « MFC Class »
--- Fill the MFC Class wizard like this

--- Be careful, the field " Type ID" must be well filled, because you're going to use this ID to set the object in VBA Excel.
--- Click on finish
--- Add a method via the interface for a test (ie right click on the interface name, her it is Itest and go to add+ Method)
--- Rebuild the solution
--- In the Dll’s folder (Debug) add a .bat file with the following instructions : « regsvr32 name_of_the_dll »
--- Copy the Dll in system32 and SysWOW64 (for 64 bits systems)
--- Run the .bat file as a superUser
--- Now for Excel Debugging proceed like this :
a. Click right on the solution name and select properties

--- On the left, choose debugging and set the field "Command" with the excel executable path (.EXE complete path)
--- Click F5 your programme will lauch excel as the executable
--- Now you can add methods and properties to your class

What to do on excel side?

Open the VBA editor (Alt + F11)and click on tools + "add reference"

--- It's Ok, now you can set your COM object (the class you have created in c++ remember the class test in our exemple)

For any question, you can contact me (see the address at the footer)


Copyright : Moulong Armel Rodrigue, 2012

Contact: moulongarmel@yahoo.fr