Calling Visual Basic dll from Excel VBA code
|
|
Thread rating:  |
B-rad - 15 Jul 2008 16:29 GMT Hello Everyone,
I'm having a problem using excel vba to call the following dll code which was created as a "Class Library" using Visual Basic 2008 Express Edition (note: "Class Library" was the only project choice that I saw that created a dll). _________________________________________________________ Public Class Class1 Public Sub a1_home_cell(ByVal jun As Excel.Workbook) MsgBox("You're In!") ' returns each sheet to the home position Dim sh As Excel.Worksheet 'Dim jun As Excel.Workbook
For Each sh In jun.sh 'ActiveWorkbook.Worksheets() sh.Activate() sh.Range("A1").Select() Next sh
End Sub End Class _________________________________________________________
However, when I attempt to call it from an excel 2000 vba sub routine as follows:
__________ Public Declare Sub a1_home_cell Lib "C:\Documents and Settings\b-rad\My Documents\Visual Studio 2008\Projects\junk\junk\obj\Release\junk.dll" (current_workbook As Workbook)
Sub attempt5() Call a1_home_cell(ActiveWorkbook) End Sub __________
I get an error stating: "Run-time error ?453?: Can?t find DLL entry point a1_home_cell in C:\Documents and Settings\b-rad\My Documents\Visual Studio 2008\Projects\junk\junk\obj\Release\junk.dll"
From the messagebox I placed at the beginning of the dll, I see that, just as the error message states, its not even getting into the dll.
Any ideas?
Thanks, B-rad
Dick Grier - 15 Jul 2008 16:54 GMT Hi,
A simple class library is not sufficient.
Your dll must include a COM interface. Does it? It also must be registered (REGSVR32.EXE, or equivalent). If so, then you add a reference to the dll using the Project/References menu, browse to the location of the dll and click OK.
Then create a program variable that uses this new object. For example,
Dim MyClass As New JunkClass.whatevernameisthepublicinterface
Then, call MyClass properties, methods, etc.
 Signature Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. See www.hardandsoftware.net for details and contact information.
B-rad - 15 Jul 2008 17:10 GMT Thanks for the reply,
I'm very new to this type of programming. How do I make a com interface and register it?
Paul Clement - 15 Jul 2008 17:48 GMT ¤ Thanks for the reply, ¤ ¤ I'm very new to this type of programming. How do I make a com interface ¤ and register it? ¤
The following should help:
http://msdn.microsoft.com/en-us/library/ms973802.aspx#callnetfrcom_topic2
Paul ~~~~ Microsoft MVP (Visual Basic)
Karl E. Peterson - 15 Jul 2008 21:20 GMT > Thanks for the reply, > > I'm very new to this type of programming. How do I make a com interface > and register it? Easiest way would be to use Visual Basic (File/Make DLL), not the johnny-come-lately-wannabe-pretender that goes by that misnomer.
 Signature .NET: It's About Trust! http://vfred.mvps.org
B-rad - 16 Jul 2008 14:42 GMT Karl,
Thanks for the reply. The File/Make DLL doesn't seem to be an option in Visual Basic 2008 Express Edition. Is it available in VB 6.0?
Thanks
B-rad - 16 Jul 2008 14:52 GMT Karl,
Thanks for the reply. The File/Make DLL doesn't seem to be an option in Visual Basic 2008 Express Edition. Is it available in VB 6.0?
Thanks
Dick Grier - 16 Jul 2008 17:22 GMT What Karl means is that it is easier to create an ActiveX dll in VB6 that can be called from Excel, than in .NET. He is correct (I'd choose VB6, unless I needed .NET for some feature that it makes easy, such as the use of a web service).
Dick
 Signature Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. See www.hardandsoftware.net for details and contact information.
B-rad - 16 Jul 2008 19:11 GMT Dick,
Thanks for the reply. I was using vb 2008 express edition just because that's the only one I have access to (its free). Does VB 6 have to be purchased?
Thanks
Michael Cole - 17 Jul 2008 02:54 GMT > Dick, > > Thanks for the reply. I was using vb 2008 express edition just > because that's the only one I have access to (its free). And there is a reason why it is free. No one would pay for it...
> Does VB 6 > have to be purchased? Yes. People will pay for that one...
 Signature Regards,
Michael Cole
Bruce M. Axtens - 18 Aug 2008 04:20 GMT Message by Michael Cole <noone@microsoft.com.au> on: 17/07/2008 11:54:23 AM
>> Does VB 6 >> have to be purchased? > >Yes. People will pay for that one... Actually, there is a free one, now that VB6 has slipped off MS's radar.
Bruce.
-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
Michael Cole - 19 Aug 2008 01:07 GMT > Message by Michael Cole <noone@microsoft.com.au> on: 17/07/2008 > 11:54:23 AM [quoted text clipped - 6 lines] > Actually, there is a free one, now that VB6 has slipped off MS's > radar. A free *legal* full copy of VB6 available? Please tell me where?
 Signature Regards,
Michael Cole
axtens - 20 Aug 2008 16:32 GMT > > Message by Michael Cole <no...@microsoft.com.au> on: 17/07/2008 > > 11:54:23 AM [quoted text clipped - 13 lines] > > Michael Cole I'm not sure what its legal status is. Can't read Spanish for one thing. Anyway, this is where it was found <http://www.luchoedu.org/blog/2008/01/20/pack-visual-studio-6-portable/
Kind regards, Bruce.
Dick Grier - 17 Jul 2008 16:45 GMT Yes.
So, if you want to use a free version, you will have to use the information that Paul mentioned.
Dick
 Signature Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March 2006. See www.hardandsoftware.net for details and contact information.
|
|
|