473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Error when calling vb dll subroutine from excel vba

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 ***
Aug 6 '08 #1
17 3099
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 ***
Aug 6 '08 #2
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 ***
Aug 6 '08 #3
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 ***
Aug 6 '08 #4

Kerry,

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

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Aug 6 '08 #5
Shouldn't it be "new implimentIDemo"? Your IDemo is an interface, so you
have to create an actual class instance and cast it.

"Blaine" wrote:
>
Kerry,

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

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Aug 7 '08 #6
On Aug 6, 9:11 pm, Blaine <anonym...@devdex.comwrote:
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
Aug 7 '08 #7

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,
*** Sent via Developersdex http://www.developersdex.com ***
Aug 7 '08 #8

Hello Onur,

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

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Aug 7 '08 #9
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.
"Blaine" wrote:
>
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,
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #10

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!
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #11
Take a look at this site: http://dependencywalker.com/faq.html.

It looks like you have some depenency on IE 7 perhaps.

DWMAPI.dll is a Vista dll, to my knowledge. Are you running on Vista?
"Blaine" wrote:
>
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!
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #12

Mike,

I'm using Windows XP, SP2
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #13
Searching for DWMAPI.Dll shows a lot of people running into this issue, but I
cannot say that I ever have. Here is a thread with a lot of information on
the subject:

http://forums.msdn.microsoft.com/en-...5f2bc2/#page:1

"Blaine" wrote:
>
Mike,

I'm using Windows XP, SP2
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #14

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
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #15

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
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #16
I'm running low of ideas at the moment :( Sorry!

"Blaine" wrote:
>
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
*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #17
Mike,

Thanks for trying. Let me know if you think of anything.

*** Sent via Developersdex http://www.developersdex.com ***
Aug 8 '08 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Giulio Belrango | last post by:
Hi I need someones help I'm working in an IBM 390 batch environment. What I'm trying to do is to call from a non DB2 COBOL program a DB2 COBOL program that will access a table and perform an...
12
by: Bigdakine | last post by:
I don't know if this is the right forum for this, and if not please suggest one which fits. I have to call a fortran sub routine from a C main program. The fortran subroutine statement is ...
2
by: Rob G | last post by:
Hi, I am new to this ASP.NET thing and while going very slow, I am learning. Then I got a Configuration Error out of nowhere when I ran my project. I do have Excel as reference (but I haven't...
6
by: Rich Wallace | last post by:
Hi all, I have a VB app that runs and manages individual XLS files within a single COM object. Upon processing the final fie, I attempt to close out the EXCEL object and release it using...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: Ned Balzer | last post by:
I have a puzzling problem. I am using some code I found in another thread here to output the results of a gridview to excel. Here is the subroutine: Sub SendToExcel(ByVal Source As Object,...
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
1
by: urkel | last post by:
Hi everyone, I critically need help to solve this problem related to pointer in C++ Basically, I have a C/C++ program "retardselfenerg" calling a Fortran 90 subroutine "surfGF4.f90". i am so...
2
by: Spence5 | last post by:
I've created the following dll in vb 2008 which doesn't offer an easy com template/project, thus I used project type "Class Library". Public Interface IDemo Sub doSomething() End Interface...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.