Solved

Reference is not visible in VB6

Posted on 2010-11-17
8
456 Views
Last Modified: 2012-08-14
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
Comment
Question by:mpdillon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34159641
0
 

Author Comment

by:mpdillon
ID: 34160093
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
 

Author Comment

by:mpdillon
ID: 34160106
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mpdillon
ID: 34160163
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
 
LVL 17

Expert Comment

by:Zhaolai
ID: 34161319
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34162375
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
 

Author Closing Comment

by:mpdillon
ID: 34163373
CodeCruiser,
Thanks again. I was not deleting the newly created class and ADDing a COM Class. That is a great article.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34163409
Glad its sorted :-)
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question