Method 'frames' of object 'JScriptType

2019-06-10 10:26发布

问题:

I am working on automation of internet explorer 9 through excel VBA, it throws an error when I reach on the last line below:

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://example.com/Main.asp"

'delay till readystate is complete

Set doc = ie.document
Set doc1 = doc.frames(2).document 'here comes the error

can anyone please help?

回答1:

i Have face the same issue and it got resolved

This will work for IE 10+

Set doc = ie.document.frames

Set doc1 = doc.frames(2)

For the script element, readyState is no longer supported. Starting with Internet Explorer 11, use onload

IE 11 has different ways to access attributes



回答2:

I had the same problem with some Excel VBA code after migrating to IE11. This is what I had to do to fix it:

old code which worked in IE8 but threw the error in IE11

Set objCollection = IE.Document.frames(0).Document.getElementsByTagName("span")

new code which works in IE11 (I had to add a reference to Microsoft HTML Object Library under tools/references)

Dim htmlDoc As MSHTML.HTMLDocument
Dim htmlWindow As MSHTML.HTMLWindow2
Set htmlDoc = IE.Document
Set htmlWindow = htmlDoc.frames(0)
Set objCollection = htmlWindow.Document.getElementsByTagName("span")