Results 1 to 3 of 3

Thread: VB.Net DLL in VBA

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    12

    VB.Net DLL in VBA

    Hi
    somebody please help me, how to access the DLL created in VB.Net from VBA. I created the class library in VB.Net2008. It works fine if I call the DLL from another VB.Net program. When I try to use it in VBA, it is not working, when I searched other websites, there are some many confusing explanations about COM, compile, etc.
    I have a function

    Class1
    private function adduk(a as integer, b as integer)
    dim c as integer
    c=a+b
    return c
    End Function
    End Class1

    In VBA I called the dll as
    Public Declare Function additionuk Lib "d:\ClassLibrary1.dll" (aa As Integer, bb As Integer) As Integer

    and in the main module I called like
    c = adduk(a,b)

    But it is not working. Somebody please help me how to find a solution.

    Thanks
    Deuche

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: VB.Net DLL in VBA

    I assume that is a simplified example? If not then why bother with a DLL in the first place - just put that code in your VBA project.

    I haven't used VBA for a long time but I assume its still COM based, in which case you'll need to enable COM interop. Go to your projects properties.. on the application tab click "Assembly Information" and then make sure "Make assembly COM-visible" is checked.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    12

    Re: VB.Net DLL in VBA

    Quote Originally Posted by keystone_paul View Post
    I assume that is a simplified example? If not then why bother with a DLL in the first place - just put that code in your VBA project.

    I haven't used VBA for a long time but I assume its still COM based, in which case you'll need to enable COM interop. Go to your projects properties.. on the application tab click "Assembly Information" and then make sure "Make assembly COM-visible" is checked.
    Hi keystone_paul,
    Thanks for your reply. I gave here a small example to understand the process. In my project it has so many functions which are used for Hardware interfaces. I don't want to confuse others with my big codes.
    I tried the same way you explained "COM-visible", it is enabled and built the DLL file. I don't know how to call the DLL and its function in VBA.
    Thanks
    Deuche

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width