Serving the Quantitative Finance Community

 
User avatar
Domingues
Topic Author
Posts: 0
Joined: November 27th, 2002, 12:25 pm

1st steps to create dll with VBA

November 28th, 2002, 12:21 pm

I have been created some macros but I neet to protect them. I have read the best way is to transfer some things to a dll file. How can I create the dll file with the MS Office XP VBA editor? Thank you in advance.
 
User avatar
PinballWizard
Posts: 4
Joined: March 13th, 2002, 4:36 pm

1st steps to create dll with VBA

November 28th, 2002, 11:39 pm

Hi Domingues,You cannot create a DLL with Office VBA (unless you have the 'Developer Edition'). One would typically use Visual Basic 6 (as in Visual Studio 6) or Visual C++ 6. This would allow you to create a COM/Active X dll. If you have Visual Studio, then creating a VB DLL is simply a matter of selecting the ActiveX DLL project type. Hope this helps.P.
 
User avatar
csparker
Posts: 0
Joined: October 3rd, 2001, 7:53 am

1st steps to create dll with VBA

November 29th, 2002, 6:58 am

AM I right in thinking that you could develop and test the core VB code of a DLL using VBA by creating a class module. The text of the module has to be exported (cut / pasted) into VB and then compiled into a DLL though. I have done the reverse of this to test a DLL - paste the class module from VB to VBA, add a VBA wrapper to the class module's code and get going on it. A useful trick as you can create test cases by entering data into cells, and having your wrapper function reference those cells.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

1st steps to create dll with VBA

November 29th, 2002, 1:44 pm

However, VB (not]VBA)will compile your code into an ActiveX object, which is really a DLL.Upon startup, VB will let you select "ActiveX DLL" as a type of projectSet the name of the class to "Classic", and Using the Project..Properties menu item, set the Project Name toDemoDll.Pour in your code, a good idea to start simple like withOption ExplicitFunction MySQrt(x As Double) As DoubleIf x < 0 Then MySQrt = 0Else MySQrt = Sqr(x)End IfEnd FunctionOnce you've got it to compile you need to run a command line appRegSvr32 DemoDLL.dllIn Excel you need to use menu Tools...References to add a reference to your new library.If you've followed my names then you can write Dim MyLib As New Classicplo = MyLib.MySQrt(-12)VB compiles using a variant upon the C++ compiler which not only hides your code pretty damn well, but may well make it run faster.DominiConnor
 
User avatar
Domingues
Topic Author
Posts: 0
Joined: November 27th, 2002, 12:25 pm

1st steps to create dll with VBA

November 29th, 2002, 3:55 pm

Thank you very much guys!I'll follow the tips.