• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

Reference is not visible in VB6

I have created a Class project in VB.net (vs 2009). I just used regasm to create the .tlb file (thanks for those instructions. I got them here). I have created a strong key, Emailinvoices.snk.pfx.
However after referencing the .tlb file in Excel VBA, I try to create an object with:

Dim objEmailInvoices as new ______  <== But EmailInvoices is not visible in the Intelisense help.

The Properties and Modules of the Class are all declared as Public. What am I missing?

  • 4
  • 3
1 Solution
mpdillonAuthor Commented:
The MS article was very helpful. All of the ComVisible attributes were set to TRUE (that is the default but I checked). My Class had another property COMClass and it was set to FALSE. I changed it to TRUE. That did not solve the problem.

I looked at the AssemplyInfo.vb file (use the Show all files button of the Project). I found a line:
<Assembly:ComVisible(False)>   I changed this to True. That did not solve my problem.

The MS article stated the need to have an empty procedure named NEW. That rang a bell so I compared the old project to the new one. To the new project I added:

Public Sub new()
End Sub

After this I was able to see the Class and its Properties in VBA.

After each change, I Ran a Build on the project. Then I regenerated the .TLB file with Regasm. Was the regeneration of the .Tlb file necessary?

Lastly, I compared this project to the one I did several years ago. The older VS 2008 project had the following code at the top of  the Class Module

<Assembly: ClassInterface(ClassInterfaceType.AutoDual)>
<ComClass(SendEmailClass.ClassId, SendEmailClass.InterfaceId, SendEmailClass.EventsId)> _
Public Class SendEmailClass

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class
    ' and its COM interfaces. If you change them, existing
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "187d8992-b211-44f7-9bf0-9be98129905c"
    Public Const InterfaceId As String = "2ca24656-528b-42a2-bed0-a1452d70c0de"
    Public Const EventsId As String = "e8f8d4e7-ee4d-47e8-8b30-765111c27ec0"
#End Region

    ' A creatable COM class must have a Public Sub New()
    ' with no parameters, otherwise, the class will not be
    ' registered in the COM registry and cannot be created
    ' via CreateObject.
    Public Sub New()
    End Sub

The New project only has:

<Microsoft.VisualBasic.ComClass()> Public Class Class1
    Public Sub New()
    End Sub

Do I need to modify the new project? Are there negative consequences for how I have it currently structured? If I do need to get the "Assembly .." code into the new project, can you point me to an article that explains how to do it?

mpdillonAuthor Commented:
P.S. This code is not intended to run in Excel. I just test in Excel because it is easier to do than to use the embedded VBA in the ERP solution I am working with.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

mpdillonAuthor Commented:
The Class and its properties are now visible. However, when I try to access the Properties I receive the following error:
"The Class does not support Automation or does not support the expected interface"

Here is my code:

Dim objPrintInvoices As New EmailInvoices.Class1

With objPrintInvoices
    .DatabaseNameString = "demodata"
    .InvNoString = "3741"
    .ReportTypeInteger = 0
    .ServerNameString = "fs-eatemsql"
    MsgBox "Invoice Pdf file = " & .PDFFileNameString
End With

It gives the error message at the WITH line.

Make sure to check "Register for COM Interop" in Project Properties->Compile, see attached screen shot. A .tlb file will be generated automatically.
Notice this point in MS article

"Use the COMClass template in Visual Basic .NET or in Visual Basic 2005. When you add a new class that you intend to expose to COM applications, consider using the COMClass template that is provided by Visual Basic .NET or by Visual Basic 2005. The COMClass template creates a class that includes the COMClassAttribute attribute and generates GUIDs for the CLSID, the Interface ID, and the Event ID that are exposed by your type. Additionally, the COMClass template creates a public constructor without parameters. This is the easiest way to create a new class that follows the guidelines for creating COM callable types."

Did you use the COMClass template?
mpdillonAuthor Commented:
Thanks again. I was not deleting the newly created class and ADDing a COM Class. That is a great article.
Glad its sorted :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now