0

如何将 ThisWorkbook 中的类对象传递给 UserForm?

我收到以下错误:

本工作簿中:

Dim MainObject As MyClass
Set MainObject = New MyClass

Public Sub ShowMyForm()
  Dim frmMyForm as MyForm
  Set frmMyForm = New MyForm
  frmMyForm.FormObject = MainObject  ' *<-- Run-time Error '13': Type mismatch*
End Sub

MyForm中:

Private p_Object As MyClass

Property Get FormObject() As MyClass
  Set FormObject = p_Object
End Property

Property Set FormObject(ByRef Value As MyClass)
  Set p_Object = Value
End Property
4

1 回答 1

0

当您分配对象时,您需要使用 Set 关键字,如下所示:

Set frmMyForm.FormObject = MainObject
于 2013-03-26T10:39:20.353 回答