Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 13th, 2004, 10:21 AM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create a DLL with VB and use it from VBA


I wish to write some simple functions in VB then call them from VBA.
Got a Wrox VBA book that tells be how to make an API call to a DLL.
Also, I have a completitors book called Visual Basic 6 Bible, doesn't live up to it's name as not one reference to DLL's in the whole book.

Could someone do a VB Hello World function and show me the process of converting it to a DLL and then calling it up from within VBA

Thanks!



 
Old May 15th, 2004, 01:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is indeed a very simple example of a dll, and it would be rather silly to use a dll for this purpose. It's only to show you the process. And I'm not especially experienced with this. But we'll all have to start somewhere ;)

In VB6 add a new ActiveX DLL and name it TC1 in the properties window.

This is the code for the class:

'-------------------
Option Explicit

Private m_FName As String
Private m_Lname As String

Public Property Let FirstName(First As String)
    m_FName = First
End Property

Public Property Let LastName(Last As String)
    m_Lname = Last
End Property

Public Property Get BothNames() As String
    BothNames = m_FName & " " & m_Lname
End Property
'--------------


From the Project menu select Project1 Properties (Bottom last menu item) and as Project name enter: projTC1

Then select File - Make ProjTC1.dll and remember where the dll is placed, e.g. Desktop.

Close VB and Open Excel, open a new Workbook and from VBEditor add a module to this.

Open Tools-References and select Browse. Browse to your Desktop and select the new projTC1.dll.

Make a Sub like this:

Option Explicit
Sub test1()

Dim TC As TC1
Set TC = New TC1

TC.FirstName = Cells(1, 1).Value
TC.LastName = Cells(1, 2).Value

Cells(1, 3).Value = TC.BothNames

Set TC = Nothing
End Sub

Now enter your firstname in A1, lastname i B1 and run the macro. You should see your full name in C1.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a .DLL callable from VBA Dan412 VB How-To 1 August 20th, 2007 10:32 AM
Calling VB.Net Dll from Excel VBA zyphax Pro VB.NET 2002/2003 4 July 16th, 2007 08:41 PM
Create a DLL in ASP/VB?? ram.marella Classic ASP Basics 0 June 13th, 2007 01:20 AM
How to convert .NET dll to COM dll used by VB 6.0 gvprashanth .NET Framework 1.x 0 December 4th, 2006 05:05 AM
Create textbox in the VB Dll Using by ASP Andraw Classic ASP Components 0 February 22nd, 2005 01:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.