&引用;“所需对象”;VBA中的错误,但I';m使用集合指定对象
我有这个功能:&引用;“所需对象”;VBA中的错误,但I';m使用集合指定对象,vba,excel,Vba,Excel,我有这个功能: Public Function nextBlock(featureBlockObj As FeatureBlock, endFeatureNumber As Variant) As FeatureBlock Dim downstreamFeatureNumber As Variant 'get the feature number that this endpoint connects to downstreamFeatureNumber = featureBlockObj.
Public Function nextBlock(featureBlockObj As FeatureBlock, endFeatureNumber As Variant) As FeatureBlock
Dim downstreamFeatureNumber As Variant
'get the feature number that this endpoint connects to
downstreamFeatureNumber = featureBlockObj.connectedFeatureNumber(endFeatureNumber)
'if it connects to a feature number, look that feature number up in blockDict
If isNumericNonBlank(downstreamFeatureNumber) Then
Set nextBlock = blockDict(downstreamFeatureNumber)
'if it does not connect, this is the last block in the sequence
Else
Set nextBlock = Nothing
End If
End Function
blockDict
是一本字典<代码>功能块是用户定义的类
这一行:
Set nextBlock = blockDict(downstreamFeatureNumber)
正在抛出错误:
Object required.
我已经验证了以下内容:
作为键存在于downstreamFeatureNumber
blockDict
是类型为blockDict(下游特征编号)
FeatureBlock
那么为什么我不能使用
Set
将blockDict()
引用分配给nextBlock
?显然,blockDict(downstreamFeatureNumber)
什么都不是,这是您的问题。在尝试分配给nextBlock
之前,需要对其进行限定(如果不应该发生,则这是一个完全不同的问题,而不是VBA问题)
您在何处定义和设置“blockDict”?在何处以及如何声明
nextBlock
?blockDict(下游特征编号)似乎存在问题。我将尝试隔离正在发生的事情,并将问题作为一个独立的示例进行修改。
If isNumericNonBlank(downstreamFeatureNumber) _
AND (Not (blockDict(downstreamFeatureNumber) Is Nothing)) Then