• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • 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?

thanks,
pat
0
mpdillon
Asked:
mpdillon
  • 4
  • 3
1 Solution
 
mpdillonAuthor Commented:
CodeCruiseer,
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()
 MyBase.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()
        MyBase.New()
    End Sub


The New project only has:


<Microsoft.VisualBasic.ComClass()> Public Class Class1
    Public Sub New()
        MyBase.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?

thanks,
pat
0
 
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.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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"
    .ProcessInvNo
    MsgBox "Invoice Pdf file = " & .PDFFileNameString
End With

It gives the error message at the WITH line.

0
 
ZhaolaiCommented:
Make sure to check "Register for COM Interop" in Project Properties->Compile, see attached screen shot. A .tlb file will be generated automatically.
ScreenShot.png
0
 
CodeCruiserCommented:
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?
0
 
mpdillonAuthor Commented:
CodeCruiser,
Thanks again. I was not deleting the newly created class and ADDing a COM Class. That is a great article.
0
 
CodeCruiserCommented:
Glad its sorted :-)
0
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

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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