Call VB6 DLL from VBA wrapper

J

jbscotland

Dear All,

I have a VB6 DLL (called myAddin) that has a sub (called InsertRows).
I need to make the DLL available to Excel 2000 users so I need to
create a VBA Wrapper (called vbaInsertRows)

I'm having trouble calling the DLL sub. I have tried it using a
function and that works fine.

Any help greatly appreciated.

Thanks

jb
 
B

Bob Phillips

The sub works exactly the same as the function. What are you using to call
it?

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
C

Chip Pearson

First of all, what do you mean by "having trouble"? Does it simply do
nothing? Run-time error? Compiler error? Incorrect action? You might want to
post the procedure declaration so we can see how the function is declared.

To use a VB6 ActiveX DLL, you first need to register the DLL with Windows.
With Excel closed, go to the Windows Start menu, choose Run, and enter

RegSvr32 "C:\YourFolder\YourDLL.DLL"

You should get a message like "DllRegistryServer Of YourDLL.DLL Succeeded".

Then, open Excel and VBA. In the VBA Editor, go to the Tools menu and choose
References. There, scroll down to your DLL Project name (which may or may
not be the same as the DLL file name) and check that box. Then you'll need
to declare a variable of the creatable object type on the DLL and then set
that variable to a new instance of the creatable object. For example,

Public ProjObj As MyProj.MyProjObject

Sub Initialize()
Set ProjObj = New MyProj.MyProjObject
End Sub

Sub TestIt()
Dim Res As Variant
Res = ProjObj.MyFunction(1234)
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top