Saturday, September 05, 2009

How to use .NET assembly in VBA

Example with detailed steps: Consuming .NET components within Access/VBA

3 comments:

  1. Update from John Mishefske:
    I had to modify the VBA code in the modBigInt module in the
    BigMathInAccess.mdb file to successfully run the sample.

    The ProgID for this class library is BigIntX and the main class is
    BigInt so I had to modify this:

    Public Sub earlybinding()

    Dim big As New BigInt.BigInt

    Debug.Print big.multiply("3", "4", 10)
    Debug.Print big.divide("16", "2", 10)
    Debug.Print big.modulo("9", "10", 10)

    End Sub

    to this

    Public Sub earlybinding()

    Dim big As New BigIntX.BigInt

    Debug.Print big.multiply("3", "4", 10)
    Debug.Print big.divide("16", "2", 10)
    Debug.Print big.modulo("9", "10", 10)

    End Sub

    NOTE: The X after "BigInt" in the ProgID.

    and once I did the VBA compiled and ran successfully.

    Great sample and demonstrates that Access can potentially do anything
    that a .Net program can!

    ReplyDelete
  2. Could you help me on this :
    Whatever I do, I get the followin error when using the object on VBA :

    "File or assembly name BigIntX, or one of its dependecies, was not found."

    This occurs with the eraly binding and late dinding versions of the object.
    Note that they appear properly in the object browser.

    Even stranger, if I want to regenerate the TLB with regasm, I have to close excel, which seems to indicate the tlb was properly loaded...

    Any idea ?

    ReplyDelete
  3. I've been scratching the surface of .net but would like to learn more. I like that it can integrate with Access through VBA.

    ReplyDelete