+ Reply to Thread
Results 1 to 3 of 3

Creating DLL's in Visual Basic Express (2010) for use in Excel - Help!

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    Shanghai
    MS-Off Ver
    Excel 2007
    Posts
    2

    Creating DLL's in Visual Basic Express (2010) for use in Excel - Help!

    I'm not sure if this problem is an Excel VBA problem or Visual Basic problem or a combination of the two. But I hope someone can help!

    I'm trying to create code in Visual Basic Express (2010) that I can call from Excel VBA programs - VBA is too slow for the calculations. This is the first time I've used anything .NET related, so I'm starting with something really simple. And failing.

    So far I haven't succeeded in creating a DLL that I can using in Excel VBA.
    Following examples, what I have managed to do is:
    1) Create a class in VB Express (2010), build it as a DLL and then use this class in another VB project. This worked smoothly - I just had to add a reference to the 2nd project which used the DLL. However, I'm unable to use this DLL in VBA.
    2) I have also managed to create a DLL in VC++ Express (2010) and call this from Excel VBA. I never even had to add the DLL as a reference. I simply had a line of code in VBA

    Declare Function timestwo Lib "D:\TestC++NET\TestCDLL\Debug\testCdll.dll" _
    Alias "_timestwo@8" (ByVal x As Double) As Double

    In this case, the DLL created in C++ contained just a single a function, not a class.

    Problems
    (1) When I try and add the DLL I created in (1) as a reference to VBA, I get an error in the VBA IDE which says "Can't add a reference to the specified file." (This seems a little odd because I had no problem adding the DLL as a reference to another VB 2010 project.)
    (2) I do see references on the web to the fact that I may have to register the DLL. When I run Regsvr32 I get the error message "MyDLL.dll was loaded but the DLLServerRegister entry point was not found. This file can not be loaded."
    (3) When looking at the Project Compile screen in Visual Basic Express 2010, I see fields like "Build Output Path" and various compile options. However, I do NOT see a "Register For COM Interop". (Which some info on the web seems to indicate I need to check) MS's documentation mentions that "Register For COM Interop" setting is not available for Windows Application or Console Application projects - but mine is a Class Library.
    I also notice that both the Project "Application*" and "Compile*" tabs have an asterisk at the end of the name.
    Does this perhaps mean that the options I'm looking for are not available in the VB 2010 Express version and that I can't create a DLL with VB 2010 Express? (But it seems strange that I could get a simple C++ function to be accessible in VBA via a DLL.)

    Yours, increasingly baffled
    Hedgepiglet



    So....how do I go about creating a DLL that can actually be "seen" and used by VBA? I'd prefer not to have to register the DLL - but if I do have to, I can live with this.

    Any help, hints, tips or tricks would be gratefully appreciated!

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Creating DLL's in Visual Basic Express (2010) for use in Excel - Help!

    Do these help?

    http://support.microsoft.com/kb/317535
    http://www.mrexcel.com/forum/excel-q...int-error.html
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-31-2012
    Location
    Shanghai
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Creating DLL's in Visual Basic Express (2010) for use in Excel - Help!

    Hello Andy

    Thanks for the links. I hadn't come across either of them.

    I've seen something very similar to the advice suggested in the first - but I can't follow it because I can't find the "Register For COM Interop" checkbox which seems to be one of the necessary settings.
    The second link looks potentialy quite helpful. It doesn't quite answer my questions but hopefully it'l give me enough information to solve the problem.

    Once again, thanks for your help.

    Regards
    HedgePig

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1