声明包含后期绑定字典对象的自定义数据类型

Declaring a custom data Type containing a late-bound Dictionary Object

是否可以声明自定义类型,其元素之一是后期绑定的字典对象?例如在标准模块或 Class 模块中:

Private Type InternalData
    sName as String
    cSheets as Collection    'cSheets as New Collection
    wBook as Workbook
    bFiles as CreateObject("Scripting.Dictionary")    'bFiles as New CreateObject("Scripting.Dictionary")
End Type

或者有其他方法吗?请注意,我不想提前绑定词典。

您将像处理工作簿对象一样处理字典对象。将您的字典声明为 Object 类型,然后在其他地方对其进行初始化。例如,在一个表单中你可以有:

Private Type InternalData
    sName As String
    cSheets As Collection
    wBook As Workbook
    bFiles As Object
End Type

Public Sub TryIt()
   Dim id As InternalData
   Set id.bFiles = CreateObject("Scripting.Dictionary")
   id.bFiles.Add Key, Value
End Sub

根据评论,以下是使用 class 的方法。在 Class 模块中:

Public sName As String
Public cSheets As Collection
Public wBook As WorkBook
Public bFiles As Object

Private Sub Class_Initialize()
   Set bFiles = CreateObject("Scripting.Dictionary")
End Sub

然后像以前一样,可能是一个表格:

Public Sub TryIt()
   Dim id As InternalData
   id.bFiles.Add Key, Value
End Sub