Thread: activeX dll
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default activeX dll

"eRic" wrote in message
...
I have build a dll by Visual basic
How can I import the dll file on runtime ?


I'm assuming your DLL contains at least one MultiUse or GlobalMultiUse
class and that it's been properly registered on the machine where you want
to use it. Otherwise you won't be able to access it from VBA. There are one
of two ways to use an ActiveX DLL from VBA:

1) Set a reference to the DLL using the Tools/References menu in the Visual
Basic Editor. You can then declare object variables to represent objects in
your DLL and otherwise use it exactly like you'd use any other class. You
should always prefix any class names from your DLL with the name of the DLL
itself to avoid any name collisions. For example, if you DLL is called MyDll
and it has a public class called MyClass you would do this:

Dim clsClassRef As MyDll.MyClass
Set clsClassRef = New MyDll.MyClass
''' Use the clsClassRef variable here
Set clsClassRef = Nothing

2) You can use your DLL without a reference by using the late-binding
technique. This requires you to declare all the variables that reference
your DLL "As Object" and use the CreateObject function to acquire references
for them. Using the same scenario as above, this would be:

Dim objClassRef As Object
Set objClassRef = CreateObject("MyDll.MyClass")
''' Use the objClassRef variable here
Set objClassRef = Nothing

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm