我正在使用 SmartyStreets API,我正在尝试测试响应以查看“delivery_line_2”字段中是否有值。尝试运行代码时,我在 VBA for Excel 中不断收到变量未定义错误。有人对最好的方法提出建议吗?我正在使用以下代码尝试访问:
Dim candidates, candidate, components, metadata, analysis As MSXML2.IXMLDOMNode
Set candidates = xmlDoc.DocumentElement
For Each candidate In candidates.ChildNodes
Set components = candidate.SelectSingleNode("components")
Set metadata = candidate.SelectSingleNode("metadata")
Set analysis = candidate.SelectSingleNode("analysis")
Cells(RowIndex, DPVColumn).Value = analysis.SelectSingleNode("dpv_match_code").nodeTypedValue
Cells(RowIndex, DPVColumn + 1).Value = components.SelectSingleNode("zipcode").nodeTypedValue & "-" & components.SelectSingleNode("plus4_code").nodeTypedValue
Cells(RowIndex, DPVColumn + 2).Value = candidate.SelectSingleNode("delivery_line_1").nodeTypedValue
**If Len(candidate.SelectSingleNode("delivery_line_2").nodeTypedValue) > 1 Then
Cells(RowIndex, DPVColumn + 3).Value = candidate.SelectSingleNode("delivery_line_2").nodeTypedValue
End If**
谢谢。