VBA的Excel – 模具和转储收集
在编写VBA时,我喜欢在开发周期中的特定点上使用less量的帮助器方法。 我最有用的是由Laravel的dd($variable)
函数启发 – 死亡和转储。 换句话说,吐出variables的输出,然后杀死进程,所以不会发生其他处理。 我用它来设置断点。
现在我现在的自定义帮助器可以转储一个variables以及一个数组,但我怎么能得到它的集合工作?
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Die and Dump ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function dd(value As Variant) Dim ArrayBoolean As Boolean Dim i As Integer ArrayBoolean = IsArray(value) ' Commence to dumping the data If ArrayBoolean = True Then For i = LBound(value) To UBound(value): Debug.Print (value(i)): Next Else Debug.Print (value) End If ' Now Die! End End Function
我已经尝试了以下内容:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Die and Dump a Collection ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function ddc(value As Collection) Dim coll As Variant ' Dump For Each coll In value Debug.Print coll Next coll ' Now Die! End End Function
但是,当我做Helpers.ddc (objectsInWorkbook)
我得到一个Argument not optional
错误,但Helpers.dd(objectsInWorkbook.count)
返回一个整数5(集合中的对象的数量)
代替
Helpers.ddc (objectsInWorkbook)
使用
Helpers.ddc objectsInWorkbook
您应该调用该函数,而不是只键入Helpers.dd(objectsInWorkbook) 。
Call Helpers.ddc(objectsInWorkbook)