Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleUse a Visual Basic DLL file in an Excel spreadsheet
KeywordsDLL, Excel
CategoriesOffice, Software Engineering
 
Before you start this, you should consider implementing the DLL's features within Excel using VBA. That is a lot less complicated although a DLL may give you better performance for very complicated calculations.

In Visual Basic:

  1. Create a new ActiveX DLL project.
  2. Change the name of the default class to the name you want your server class to have. For this example, TestClass.
  3. In the Project menu, select the Properties command at the bottom.
    1. Set the Project Name to the name you want the server DLL to have. For this example, MyTestServer.
    2. Set the Project Description to the string you want to see when you select the DLL reference in Excel. For this example, My Test Server.
  4. In the File menu, select the Make command to compile the DLL.

In the Excel workbook:

  1. Open Tools\Macro\Visual Basic Editor.
  2. In the Tools menu, select References. Locate the server class you created in Visual Basic and select it. If it isn't in the list, click Browse and select the DLL.
  3. Add a module to the workbook. Create a function that makes an instance of the server class and uses the instance's methods. The following example creates an instance of the TestClass class in the DLL project named MyTestServer. It then calls the object's SquareMe function.
 
' Execute the MyTestServer.TestClass.SquareMe method.
Public Function CallSquareMe(ByVal v As Single) As Single
Dim obj As MyTestServer.TestClass

    Set obj = New MyTestServer.TestClass
    CallSquareMe = obj.SquareMe(v)
End Function
 
  1. Use the function in cell formulas as in:

        =CallSquareMe(C7)
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated