0

VBA では、getElementByID("id_name") を使用し、id が存在しない場合、関数は null ではなく何も返しません。これにより、DOM がまだ要素をレンダリングしていないのか、それとも要素が本当に存在しないのかがわからないままになります。仕様では NULL を返す必要があり、NULL は Nothing と等しくないようです。だから私の質問は、この DOM 関数が NULL を返すか、何も返さないか、それとも私が見逃しているものに依存しているのかということです。ありがとう

スニピット

If Not IsNull(p_IE.Document.getElementById(MAIN_SR_CONTAINER)) Then
 ' If I do not receive NULL I want to assume that I can grab the element.
 ' Still, I verify that the element is not Nothing

 ' problem is that NULL <> Nothing so if the element does not exist my code loops for eternity
 ' I do look at the readystate of the p_IE object and wait till it = 4
 ' But the elements may be being created by embedded javascript on the fly

    Set elMainSRContainer = p_IE.Document.getElementById(MAIN_SR_CONTAINER)
    Do While elMainSRContainer Is Nothing
        Set elMainSRContainer = p_IE.Document.getElementById(MAIN_SR_CONTAINER)
    Loop

    :
    :
Else
    ' bail
End If
4

2 に答える 2

1

getElementByIdのMSDN ドキュメントには、メソッドの戻り値は IHTMLElement 型であると記載されています。これはObjectVBA の型になります。ドキュメントは、メソッドが

指定された ID を持つ最初のオブジェクトを返します。一致しない場合は null を返します。

私の推測では、VBA ではObjects保持できないNullため、Nullが として解釈されていNothingます。

変えてみます

If Not IsNull(p_IE.Document.getElementById(MAIN_SR_CONTAINER)) Then

If Not (p_IE.Document.getElementById(MAIN_SR_CONTAINER) Is Nothing Then
于 2014-11-05T05:09:53.607 に答える