Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 29-03-2012 09:38PM
    #1
    Registered Users, Registered Users 2 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