Results 1 to 4 of 4

Thread: Problem Calling .NET dll from Excel VBA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    29

    Problem Calling .NET dll from Excel VBA

    Say I have a .NET project to compile to a class library (.DLL). Here is all the code in the library:

    Code:
    Public Class GetString 
    
        Public Function GetTestString() As String 
            Return "Test String" 
        End Function 
    
    End Class
    In the build options, I have selected the library to be Registered for COM Interop. After compiling the project, I get both GetString.dll and GetString.tlb in the \bin folder.

    Now in Excel I open a new book. Go to the Vb Editor and add a reference to the GetString.tlb file in the \bin folder of my .NET solution. I then add VBA module and I put the following code:
    Code:
    Public Sub getStr() 
        Dim str As New GetString.GetString 
        Dim ws As Worksheet 
        Set ws = ActiveSheet 
        ws.Range("A1").Value = str.GetTestString() 
    End Sub
    Compile -> Save. When I run the macro, everything works perfect! The string is successfully placed in the appropriate cell.

    But NOW the part that has confused and frustrated me for a long time. I now take the Excel worksheet, the GetString.dll, and the GetString.tlb file and put them on another computer. The other computer does have .NET installed by the way. When I run the macro, I get the following error: Run-time error '429': ActiveX component can't create the object.

    This problem is a much more simplified version of what I am actually dealing with. But If someone could PLEASE tell me the exact steps to take to get this macro to work on a PC other than my own development PC, I would be very greatful.

    Thanks,
    brazilnut

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Register the tlb file......

    Regsvr32 PATH_TO_THE_TLB\GetString.tlb

    I *think* that should do it. When compiling, it will auto register it on the development machine. But for deployment, you have to tell the system where to find the files at.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2003
    Posts
    29
    Thanks so much for the reply. I have tried this in the past and I get an error. When I run Regsvr32 "PATH_TO_TLB\GetString.tlb", I get the following message:

    "PATH_TO_TLB\GetString.tlb" is not an executable file and no registraion helper is registered for this file type.

    brazilnut

  4. #4
    Addicted Member
    Join Date
    Jul 2000
    Location
    didn't decide yet
    Posts
    222
    use the attached app to register the tbl file
    Attached Files Attached Files
    Come and get our ISDN CallerID http://www.3wm.biz

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