How to use a .NET Class from VBA

D

Dave

I hope I'm in the right forum - if no, please point my to the right
one?

I have got some extensive VBA applications that are currently calling
a .dll created using Perl. It would be useful if I could convert the
Perl to VB.NET to get the same functionality I'm accessing from Perl
and perhaps afford me some other advantages, as well.

I have never used Visual Studio, but saw that I could download and
install VS 2008 beta, which I have done. Now I'm trying to create
just a small test class that I can access from VBA, and I'm having a
terrible time, at best. In VS, I can do a Build, and I can see in the
Solution Explorer that a number of files have been created, including
a .dll, manifest, etc. I have no idea what to do after that point, and
back on the VBA side, I don't seem to be able to access any kind of a
library as a Reference.

VS documentation talks about registry-free COM, but I don't understand
that at all, nor do I know if it's even applicable for what I want to
do.

Can anyone point me to a step-by-step procedure, relative to VS 2008,
that will let me call a VB.NET class method from VBA? I am so
confused by "interop," "Com-visible" etc. that I'm doing more harm
than good by thrashing around. Furthermore, most of the MSDN
documents I've accessed don't seem to be in sync with this version of
VS.

I really need some basic (no pun intended) help on this - I need
someone to lead me by the hand - can anyone help?
 
G

Guest

Hi Dave,

To use a dll from VB.net in VBA you need to make it com visible. In the
project properties window in the application tab you will see an 'advanced'
button. Click that and the dialog from that will have a checkbox at the
bottom left corner that says "make com visible" or something like that.

That is the easy part. Then you have to assign a guid to the dll, which is
not too hard - just use the system.guid generator (look in help files - I
forget off the top of my head but I think it is system.data.guid ? and write
that to the console window and write down the guid. Now you have to place
that guid in an interface in the dll. So you have to write an interface to
make this completely com visible. It actually isn't that hard except that
you will be using <> angle brackets to enclose the guid defined for the
interface. The interface will provide intellisense (dropdown list) for your
class library (dll) in vba.

You can google for class library projects in VS.Net or class library
projects that are com visible.

Rich
 
R

rowe_newsgroups

I hope I'm in the right forum - if no, please point my to the right
one?

I have got some extensive VBA applications that are currently calling
a .dll created using Perl. It would be useful if I could convert the
Perl to VB.NET to get the same functionality I'm accessing from Perl
and perhaps afford me some other advantages, as well.

I have never used Visual Studio, but saw that I could download and
install VS 2008 beta, which I have done. Now I'm trying to create
just a small test class that I can access from VBA, and I'm having a
terrible time, at best. In VS, I can do a Build, and I can see in the
Solution Explorer that a number of files have been created, including
a .dll, manifest, etc. I have no idea what to do after that point, and
back on the VBA side, I don't seem to be able to access any kind of a
library as a Reference.

VS documentation talks about registry-free COM, but I don't understand
that at all, nor do I know if it's even applicable for what I want to
do.

Can anyone point me to a step-by-step procedure, relative to VS 2008,
that will let me call a VB.NET class method from VBA? I am so
confused by "interop," "Com-visible" etc. that I'm doing more harm
than good by thrashing around. Furthermore, most of the MSDN
documents I've accessed don't seem to be in sync with this version of
VS.

I really need some basic (no pun intended) help on this - I need
someone to lead me by the hand - can anyone help?

CodeProject.Com has quite a few articles on this. Most say what Rich
has already told you, but go a bit more in-depth and oft have sample
code. Here's one of the articles, for more just do a search for
something like "com interop" or "com dll" or similar.

http://www.codeproject.com/vb/interop/csCom.asp

Thanks,

Seth Rowe
 
D

Dave

Thanks, Rich.

I'm afraid my abysmal ignorance is still keeping me from making any
progress. Bear in mind that I'm using VS 2008 Beta 2, and from my
reading of varius fora, it doesn't seem to behave the same as previous
development environments. For instance, I can find no Guid generator
tool. (And the vs 2008 Help files don't even have an entry for
"GUID") Also, I have found references elsewhere to a "register for
COM" option/setting, but I can't find that anyplace. I've seen
references to a "Build" tab in the Project Properties, but that's not
there either.

I can find some regasm's on my system, but they are in Framework 1.0
and 2.0 directories - there's no such .exe in the framework 3.5
directory.

I have built a .dll, and in the process a whole host of other files
were produced (manifests, assemblyinfo.vb, ...snk, etc.) But once I
try to go beyond that point, I'm totally lost. Any more suggestions
you can give me would be much appreciated.
 

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