473,382 Members | 1,390 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,382 software developers and data experts.

Use COM object from Excel VBA - made in .NET "ActiveX component can't create object"

I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better

I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to register for COM interop in Visual Studio

So I go into Excel (where I want to use the object). Go to VB Editor and Tools -> References and to Add Reference. I browse until I find the \bin directory of the project. Select the .dll file outputted by the program. Then click open -> I get the message "Can't add reference to the specified file." So here is my first question: Why not

So then I go to my project in Visual Studio. Highlight the project -> click properties ->go to Build -> and check "Register for COM interop" -> then I rebuild my solution. After this build there is another file in the \bin directory with the same name as the .dll but has the extension .tlb (Type Library)

So I go back into Excel. Go to VB Editor -> Tools -> References and to Add Reference. I browse until I find the \bin directory of the project. This time however I select the .tlb file outputted by the program. Then click open -> I don’t get an error message so this is good. So here is my second question: Why does the .tlb work and not the .dll at this point

Now after this step. I create the object in VBA code. Compile and run the macro and sure enough it returns the string and puts in the right cell. Great! But wait. Now many more people need this object to work with Excel

So I copy the Excel Workbook and everything in the \bin directory from my project to another person’s computer. Then I open the Excel workbook -> then to VB Editor -> References to double check the path to the .tlb file -> (then compile and save for peace of mind). But here is the big problem... when I run the macro on another person's computer I get the message "ActiveX component can't create object." And I get this at the line where I say: Set testObj = New Object

My ideas... could it be that I am an Admin on my PC but not the other? If so, how do I get around this. Or is Visual Studio doing an extra step in the compile/build process that I’m not replicating on the other PC? Does it need to be an global assembly

Also, .NET is installed on the other PC and I have tried to register the .DLL, but this is unsuccessful as well? I guess that is another question: why

If someone could help me out here I would be very grateful. I have been trying to figure out a solution for a long time. I just don’t understand why everything works fine on my PC but won't run on another

Thanks for being patient
brazilnu

Jul 21 '05 #1
2 13353
See comments in-line.

"brazilnut52" <an*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.com...
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better.
I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return
a string value. At this point I have not checked the option to register for
COM interop in Visual Studio.
What language do you use to create COM DLL in VS.NET? Unmanaged VC++? As I
know, you cannot make COM component with managed code (VC++, C#, or VB.NET).
From what you described below, it seems that you actually create managed
..NET class, NOT COM class! You cannot use .NET component unless you
export/register it for COM use with REGASM tool (it does the same thing if
you set the option to "register for COM interop" in project properties
dialog box).

So I go into Excel (where I want to use the object). Go to VB Editor and Tools -> References and to Add Reference. I browse until I find the \bin
directory of the project. Select the .dll file outputted by the program.
Then click open -> I get the message "Can't add reference to the specified
file." So here is my first question: Why not?

Of course not. It is not a COM dll, nor you did not export a COM interface
for the .NET DLL asembly with Regasm tool.

So then I go to my project in Visual Studio. Highlight the project -> click properties ->go to Build -> and check "Register for COM interop" ->
then I rebuild my solution. After this build there is another file in the
\bin directory with the same name as the .dll but has the extension .tlb
(Type Library).

..tlb file provides the interface information of COM component, so that your
VB program knows what properties and methods of a class object are available
in the dll, but actual work is done with the code in dll. With *.tlb
available, when you do the coding in VB, you can browse the class in Object
Browser window and you get Intelli-sense prompt when entering code in VB
editor. You do not really need the *.tlb if you use late-binding without
setting reference to the component.


So I go back into Excel. Go to VB Editor -> Tools -> References and to Add Reference. I browse until I find the \bin directory of the project. This
time however I select the .tlb file outputted by the program. Then click
open -> I don't get an error message so this is good. So here is my second
question: Why does the .tlb work and not the .dll at this point?

See above comment


Now after this step. I create the object in VBA code. Compile and run the macro and sure enough it returns the string and puts in the right cell.
Great! But wait. Now many more people need this object to work with Excel.
So I copy the Excel Workbook and everything in the \bin directory from my project to another person's computer. Then I open the Excel workbook -> then
to VB Editor -> References to double check the path to the .tlb file ->
(then compile and save for peace of mind). But here is the big problem...
when I run the macro on another person's computer I get the message "ActiveX
component can't create object." And I get this at the line where I say: Set
testObj = New Object.
Now that the .NET component is to be used as COM component, you need
register it as COM component with REGASM tool on each computer that runs
your app. On your development machine, VS.NET already did it for you when
you set the option "Register for COM interop"

My ideas... could it be that I am an Admin on my PC but not the other? If so, how do I get around this. Or is Visual Studio doing an extra step in the
compile/build process that I'm not replicating on the other PC? Does it need
to be an global assembly?
Also, .NET is installed on the other PC and I have tried to register the ..DLL, but this is unsuccessful as well? I guess that is another question:
why?

Since the component IS .NET class, .NET Framework is required on computers
running your app. You register the .NET component with REGASM tool, not
REGSVR32 (it is for pure COM component).

If someone could help me out here I would be very grateful. I have been trying to figure out a solution for a long time. I just don't understand why
everything works fine on my PC but won't run on another.

HTH.


Thanks for being patient.
brazilnut

Jul 21 '05 #2
See comments in-line.

"brazilnut52" <an*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.com...
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better.
I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return
a string value. At this point I have not checked the option to register for
COM interop in Visual Studio.
What language do you use to create COM DLL in VS.NET? Unmanaged VC++? As I
know, you cannot make COM component with managed code (VC++, C#, or VB.NET).
From what you described below, it seems that you actually create managed
..NET class, NOT COM class! You cannot use .NET component unless you
export/register it for COM use with REGASM tool (it does the same thing if
you set the option to "register for COM interop" in project properties
dialog box).

So I go into Excel (where I want to use the object). Go to VB Editor and Tools -> References and to Add Reference. I browse until I find the \bin
directory of the project. Select the .dll file outputted by the program.
Then click open -> I get the message "Can't add reference to the specified
file." So here is my first question: Why not?

Of course not. It is not a COM dll, nor you did not export a COM interface
for the .NET DLL asembly with Regasm tool.

So then I go to my project in Visual Studio. Highlight the project -> click properties ->go to Build -> and check "Register for COM interop" ->
then I rebuild my solution. After this build there is another file in the
\bin directory with the same name as the .dll but has the extension .tlb
(Type Library).

..tlb file provides the interface information of COM component, so that your
VB program knows what properties and methods of a class object are available
in the dll, but actual work is done with the code in dll. With *.tlb
available, when you do the coding in VB, you can browse the class in Object
Browser window and you get Intelli-sense prompt when entering code in VB
editor. You do not really need the *.tlb if you use late-binding without
setting reference to the component.


So I go back into Excel. Go to VB Editor -> Tools -> References and to Add Reference. I browse until I find the \bin directory of the project. This
time however I select the .tlb file outputted by the program. Then click
open -> I don't get an error message so this is good. So here is my second
question: Why does the .tlb work and not the .dll at this point?

See above comment


Now after this step. I create the object in VBA code. Compile and run the macro and sure enough it returns the string and puts in the right cell.
Great! But wait. Now many more people need this object to work with Excel.
So I copy the Excel Workbook and everything in the \bin directory from my project to another person's computer. Then I open the Excel workbook -> then
to VB Editor -> References to double check the path to the .tlb file ->
(then compile and save for peace of mind). But here is the big problem...
when I run the macro on another person's computer I get the message "ActiveX
component can't create object." And I get this at the line where I say: Set
testObj = New Object.
Now that the .NET component is to be used as COM component, you need
register it as COM component with REGASM tool on each computer that runs
your app. On your development machine, VS.NET already did it for you when
you set the option "Register for COM interop"

My ideas... could it be that I am an Admin on my PC but not the other? If so, how do I get around this. Or is Visual Studio doing an extra step in the
compile/build process that I'm not replicating on the other PC? Does it need
to be an global assembly?
Also, .NET is installed on the other PC and I have tried to register the ..DLL, but this is unsuccessful as well? I guess that is another question:
why?

Since the component IS .NET class, .NET Framework is required on computers
running your app. You register the .NET component with REGASM tool, not
REGSVR32 (it is for pure COM component).

If someone could help me out here I would be very grateful. I have been trying to figure out a solution for a long time. I just don't understand why
everything works fine on my PC but won't run on another.

HTH.


Thanks for being patient.
brazilnut

Jul 21 '05 #3

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

Similar topics

2
by: Mike John | last post by:
I am trying to use the shell object to send keys to the explorer browser to run the send page funcion. I am receiving the above error only when I put my html file in the web server...
5
by: Andrew | last post by:
Hi all, I am still getting into ASP/VB.net and have a concern about something I see coming. Currently our entire website is classic ASP, yet the feelings from on high is that we need to start...
0
by: Gazelle | last post by:
I have a dilemma, that I am hopping I can find some help with. He is the back story so everyone sort of understands what it is that I am trying to accomplish. My problem: I have multiple...
2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
1
by: UnaCoder | last post by:
Hi, I noticed that this particular object is only accessable if the IE security setting "Initialize and and script ActiveX controls not marked as safe" is enabled. Does windows maintain this list...
1
by: Emie | last post by:
Dear All, I would be most grateful if some one could please help me. My database was working fine untill yesterday but suddenly today when I try to click on a Find button or Search button OR even...
2
by: ironmanlarry | last post by:
Hi, I'm trying to do a mail merge from Excel to Word (programatically) and I'm having some trouble creating the Word Document Object. This line of code wordDoc = GetObject("sheet.doc") keeps...
0
by: syedsarfaraz | last post by:
Hi There! Could anybody please help regarding the below issue. We had a COM+ component deployed on Windows 2000/NT machine it was working fine, I mean when it was being invoked from other...
3
by: Keith G Hicks | last post by:
I created a dll for com (in vb.net 2005) so that I could access it's functions from an ms access app. I created the tlb file successfully. On my dev machine I referenced it in my access app and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.