472,805 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 13277
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.