在编写VBA时,我喜欢在开发周期中的特定点上调用少量的帮助器方法。我最有用的是灵感来自Laravel的dd($variable)
函数 - 死亡和转储。换句话说,吐出变量的输出,然后杀死进程,以便不进行其他处理。我用它来设置断点。VBA Excel - 模块和转储集合
现在我现在的自定义助手可以转储一个变量以及一个数组,但我怎么能得到它的集合呢?
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 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的整数(对象的集合中的量)
? –
很坦白@ Gary的学生我不知道区别 –
不要使用像'value'这样的变量名,或者像'for',dim这样的任何其他vba关键字......我怀疑在你的测试中'objectsInWorkbook'是错误的类型(或空),但它仍会引发其他错误。你的解释中缺少某些东西。而且你可以只使用一个参数而不使用'call'或使用/(')'来调用一个函数或子函数。与函数的不同之处在于,您可以分配给变量:'a = dd(x)'。 –