Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Creating a dll using VB 2010 Express to be used by VBA in Excel?

Options
  • 29-03-2012 9:38pm
    #1
    Registered Users Posts: 140 ✭✭


    Hi, hoping someone can help as this driving me insane!:(

    Firstly I’m new to programming but am eager to learn. Essentially what I want to do is have Excel (using VBA) to call on some functions from a dll. As I am somewhat familiar with VBA I decided to use VB 2010 Express to create the dll. My problem is when I go to reference the dll in the VBE in Excel it gives the error “Can’t add a reference to the specified file.”

    What have I done:
    Created a class in VB 2010 Express with the following code:

    Imports Microsoft.Office.Interop.Excel
    Public Class Class1
    Function Add2Numbers(ByVal numb1 As Double, ByVal numb2 As Double) As Double
    Add2Numbers = numb1 + numb2
    End Function
    End Class
    


    I read somewhere that I needed the Imports Microsoft.Office.Interop.Excel. No idea what this is.
    Ran Build and created the dll called TestDLLadd2numbers.dll.
    Created another Windows Form in VB 2010 Express which references this dll and it works perfectly.
    As I am using Express, when it Builds it doesn’t seem to have the option to register the dll so have done this manually using regasm from the command line. Regasm TestDLLadd2numbers.dll /tlb: TestDLLadd2numbers.tlb. This seemed to work however when I tried to reference it in Excel I got the above error.

    Is it actually possible to create a dll in VB 2010 Express that can be used by VBA Excel?
    Am I missing some code in the dll to help Excel know what’s inside?
    Am I missing something basic due to my inexperience?

    Any help would be much appreciated.


Comments

Advertisement