我正在尝试使用在vba中导出为.tlb的自定义类。我已经完成了regasm的东西,但是当我尝试在类中调用子例程时,我一直收到这个错误:
运行时错误'429':ActiveX组件无法创建对象
我在vba中引用了这个类,我已经为32位和64位CPU构建了类,但没有任何效果。无论如何,vba代码:
Sub test()
Dim test As New Mail.Class1
test.test
End Sub
和vb.net代码:
Imports System.Runtime.InteropServices
Public Class Class1
Public Sub test()
MsgBox("hello")
End Sub
End Class
答案 0 :(得分:0)
该课程不会接触到COM。最简单的方法是添加新项并选择COM类。这会生成一个类似于以下内容的类骨架:
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#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 = "e19c541f-8eda-4fdd-b030-abed31518344"
Public Const InterfaceId As String = "e2122f92-5752-4135-a416-4d499d022295"
Public Const EventsId As String = "6b03de7e-90d7-4227-90ec-9121c4ce1288"
#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
End Class
还要记得检查&#34;使程序集COM可见&#34;在“装配信息”对话框中(项目属性&gt;应用程序选项卡&gt;装配信息)
现在当你编译它并调用RegAsm时,它应该有一个这个类的入口点