Error when calling vb dll subroutine from excel vba

B

Blaine

I've created the following dll in vb 2008.
___________________________________________________________
Public Interface IDemo
Sub doSomething()
End Interface
Public Class implementIDemo
Implements IDemo
Dim varAsInterface As IDemo = New implementIDemo()
Dim varAsClass As implementIDemo = New implementIDemo()
Private Sub doSomething() Implements IDemo.doSomething
MsgBox("Hello")
End Sub
End Class
___________________________________________________________
I then used tlbexp.exe, gacutil.exe, regasm,exe, and sn.exe so that the
"doSomething" sub routine could be accessed/called from an excel vba (by
first referencing the tlb file).

My excel vba is as follows:

___________________________________________________________
Private moTemp As mydll.IDemo

Sub trial()
moTemp.doSomething
End Sub
___________________________________________________________

Excel VBA seems to recognize class and subfunction as I'm typing them,
but when I run the "trial" macro I get the following error:

"Run-time error '91': Object variable or With block variable not set"

Any ideas?

Thanks in advance,
 
K

Kerry Moorman

Blaine,

I don't program in vba, but shouldn't it be:

Private moTemp As NEW mydll.IDemo

Or at least whatever facility vba has for creating a new instance?

Kerry Moorman
 
B

Blaine

Thanks for the reply Kerry.

When I use "Private moTemp As NEW mydll.IDemo" it produces the error
"Invalid use of NEW keyword"
 
K

Kerry Moorman

Blaine,

Maybe the syntax is:

Private moTemp As mydll.IDemo

Sub trial()
Set moTemp = New mydll.IDemo
moTemp.doSomething
End Sub

Kerry Moorman
 
F

Family Tree Mike

Shouldn't it be "new implimentIDemo"? Your IDemo is an interface, so you
have to create an actual class instance and cast it.
 
K

kimiraikkonen

Kerry,

I'm still getting the "Invalid use of NEW keyword" error.

Thanks

*** Sent via Developersdexhttp://www.developersdex.com***

Hi,
My guess would be that one or more of your references may be missing.
Make sure you added proper reference to your class library in solution
explorer by clicking "show all files" and expand "references".

BTW, are you using VB6 or lower,... or VB.NET? Because when you have a
missing reference the error message would be "Type '<typename>' is not
defined" on .NET.

Hope this helps,

Onur Güzel
 
B

Blaine

Mike,

I tried:

Dim motemp As mydll.IDemo

Sub trial()

Set motemp = New mydll.implementIDemo
motemp.doSomething

End Sub

is this what you were thinking? It's giving the following error:
"File or assembly name mydll, or one of its dependencies, was not
found."

Thanks,
 
B

Blaine

Hello Onur,

I am using vb 2008 express edition (it's the only thing that I have
access to).

Thanks
 
F

Family Tree Mike

Yes, that is what I had wanted you to try, but I don't know why the variable
motemp is declared outside the sub. As to the missing dependency, you should
look at Depends.exe that comes with visual studio. I think it may come with
express, but I'm not positive. It should tell you about missing dependencies
from the dll or exe.
 
B

Blaine

Mike,

I think you may be on to something. I ran the "Depends.exe", as you
suggested, and it gave me the following warnings about my dll:

1.)Warning: At least one delay-load dependency module was not found.

2.)Warning: At least one module has an unresolved import due to a
missing export function in a delay-load dependent module.

Also it said there was an error opening file "DWMAPI.DLL", the system
cannot find the file specified.

How do I add or fix this?

Thanks!
 
B

Blaine

Mike,

Thanks for the reply. I found the "DWMAPI.DLL" file and placed it in my
system32 folder and reused "Depends.exe" and the problem went away.
However, my excel vba still gives the missing assembly or dependencies
error. Any other ideas?

Thanks,
Blaine
 
B

Blaine

Mike,

Thanks for the reply. I found the "DWMAPI.DLL" file and placed it in my
system32 folder and reused "Depends.exe" and the problem went away.
However, my excel vba still gives the missing assembly or dependencies
error. Any other ideas?

Thanks,
Blaine
 

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