2016-07-22 71 views
-1

我試圖使用在vba中以.tlb格式導出的自定義類。我也做了regasm的東西,但我不斷收到這個錯誤,當我試圖調用類中的一個子程序:當在vba中使用.net類時,ActiveX組件不能創建對象

運行時錯誤「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

使您的類'ComVisible'在regasm中使用'CodeBase' – cyboashu

+0

閱讀:[演練:使用Visual Basic創建COM對象](https:// msdn。 microsoft.com/en-us/library/x66s8zcd(v=vs.110).aspx) – TnTinMn

回答

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 

還記得您在大會信息對話框「使裝配COM可見」(項目屬性>應用程序選項卡>大會信息)

現在,當你編譯並調用RegAsm,它應該有一個這個類的入口點

相關問題