从excel vba调用vb dll子例程时出错 [英] Error when calling vb dll subroutine from excel vba

查看:124
本文介绍了从excel vba调用vb dll子例程时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb 2008中创建了以下dll。

__________________________________________________ _________

公共接口IDemo

Sub doSomething()

结束接口

公共类implementIDemo

实现IDemo

Dim varAsInterface作为IDemo =新的implementIDemo()

Dim varAsClass as implementIDemo = new implementIDemo()

Private Sub doSomething()实现IDemo.doSomething

MsgBox(" Hello")

End Sub

结束班级

__________________________________________________ _________

然后我用tlbexp.exe,gacutil.exe,regasm,exe和sn .exe以便

doSomething可以从excel vba访问/调用子例程(通过

首先引用tlb文件)。


我的excel vba如下:


__________________________________________________ _________

私人moTemp作为mydll.IDemo


子试用()

moTemp .doSomething

结束子

__________________________________________________ _________


Excel VBA似乎识别了类和子函数,因为我正在输入它们,

但是当我运行试用时宏我收到以下错误:


"运行时错误''91'':对象变量或With block变量未设置"


任何想法?


提前致谢,


***通过Developersdex发送 http://www.developersdex.com ***

解决方案

< blockquote> Blaine,


我不是用vba编程,但不应该是:


私人moTemp作为新的mydll .IDemo


或者至少vba用于创建新实例的设施是什么?


Kerry Moorman

" ;布莱恩"写道:


我在vb 2008中创建了以下dll。

__________________________________________________ _________

公共接口IDemo

Sub doSomething()

结束界面

公共类implementIDemo

实现IDemo

Dim varAsInterface As IDemo = new implementIDemo()

Dim varAsClass as implementIDemo = new implementIDemo()

Private Sub doSomething()实现IDemo.doSomething

MsgBox(你好)

结束子

结束班

__________________________________________________ _________

然后我使用tlbexp.exe,gacutil.exe,regasm,exe和sn.exe,以便

" doSomething"可以从excel vba访问/调用子例程(通过

首先引用tlb文件)。


我的excel vba如下:


__________________________________________________ _________

私人moTemp作为mydll.IDemo


子试用()

moTemp .doSomething

结束子

__________________________________________________ _________


Excel VBA似乎识别了类和子函数,因为我正在输入它们,

但是当我运行试用时宏我收到以下错误:


"运行时错误''91'':对象变量或With block变量未设置"


任何想法?


提前致谢,


***通过Developersdex发送 http://www.developersdex.com ***


感谢Kerry的回复。


当我使用私人moTemp为新的mydll.IDemo时它产生错误

无效使用NEW关键字

***通过Developersdex发送 http://www.developersdex.com ***


Blaine,

也许语法是:


私人moTemp作为mydll.IDemo


子试用()

设置moTemp =新mydll.IDemo

moTemp.doSomething

结束子


Kerry Moorman

布莱恩写道:


感谢Kerry的回复。


当我使用私人moTemp为新mydll.IDemo时它产生错误

无效使用NEW关键字


***通过Developersdex发送 http://www.developersdex.com ***


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,

*** Sent via Developersdex http://www.developersdex.com ***

解决方案

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
"Blaine" wrote:

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,

*** Sent via Developersdex http://www.developersdex.com ***


Thanks for the reply Kerry.

When I use "Private moTemp As NEW mydll.IDemo" it produces the error
"Invalid use of NEW keyword"
*** Sent via Developersdex http://www.developersdex.com ***


Blaine,

Maybe the syntax is:

Private moTemp As mydll.IDemo

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

Kerry Moorman
"Blaine" wrote:

Thanks for the reply Kerry.

When I use "Private moTemp As NEW mydll.IDemo" it produces the error
"Invalid use of NEW keyword"
*** Sent via Developersdex http://www.developersdex.com ***


这篇关于从excel vba调用vb dll子例程时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆