on 07-28-2005 4:05 PM
Hi everyone,
I am a really new at trying to call COM from VBA.
Here is what I've done.
a) I creates a Class Library in C# with a really simple method.
b) I created a tlb and snk file using sn.exe, gacutil.exe, regasm.exe.
I checked that my class is located in \windir\assembly.
c) I opend my Outlook 2002 and created a macro.
d)In the Tools->References menu, I selected the tlb file.
e) here is the code of the VBA macro:
Sub Macro1()
Dim objAdd As New ClassLibrary1.Class1
End Sub
This compile.
But, when I try to know the methods in the objAdd object...there aren't.
This object should contain the Add method to add 2 numbers.
Can someone help me with this issue ?
Thanks a lot.
Here is a sample that works for me:
[Guid("D443AD23-0914-4e0f-8FA2-8AAA472F3882")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("Demo.Class1")]
[ComVisible(true)]
public class Class1
{
public int Add(int a, int b)
{
return a + b;
}
}
If you regasm with /codebase or regasm without it and put the assembly into GAC, it works fine from Excel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The stuff in the brackets are COM-Interop-Custom attributes (namespace System.Runtime.Interop).
You don't absolutely need them, but you can better control the behavior of your COM-Interop:
[Guid("D443AD23-0914-4e0f-8FA2-8AAA472F3882")]
Defines the CLSID of the COM-Class. If not specified, the CLSID is automatically calculated as a hash from full class name and full assembly name. The advantage of specifying it is that you easier find you stuff in the registry and it remains the same if you rename something.
[ClassInterface(ClassInterfaceType.AutoDual)]
Describes the type of COM interface for the class. For VBS you need either Dual or Dispatch.
[ProgId("Demo.Class1")]
The so-called ProgID of you COM class that appears in HKEY_CLASSES_ROOOT. If you don't specify, you will get a ProgID somehow derived from the class name.
[ComVisible(true)]
Turns COM interop for the class on. If you turn off ComVisible for the whole assembly, you need to turn it on again on class level.
Well. . i´m think. that you can´t found the library.
for this check this link to follow the steps to install your library like a Component Service
http://www.easterndigitalsoftware.com/justldap/walkthrough.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.