Check with VBA if an element exists on the page

陌路散爱 提交于 2019-12-08 16:20:36

Ryan's answer is the correct.

set Element = document.getelementbyID("result_0")

Thanks for the solution. I used as follows,

If IsObject(objIE.document.getElementById("e164NumberMask")) Then
    'do true stuff
Else
    'do false stuff
End If

Posting an alternative in case top answer is not working for other people:

I was still getting run time error '91' after checking with IsObject()

IsObject() works fine if ObjIE is an InternetExplorer object but I was using an InternetExplorerMedium object and had to validate with this instead since it was returning a nothing object:

If Not objIE.document.getElementById("e164NumberMask") Is Nothing Then
    'do true stuff
Else
    'do false stuff
End If

You can try something like this.

Function objectHandler(objID)

Dim TestObj As Object

On Error GoTo Handler:

Set TestObj = ObjIE.document.getElementById(objID)
objectHandler = True
Exit Function

Handler:
objectHandler = False

End Function
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!