我在VBA中定义 MSHTML.HTMLWindow2 对象时遇到类型不匹配错误。请找到我的下面的代码。
Sub GoToWebsiteTest()
Dim appIE As InternetExplorerMedium
Dim tags As Object
Dim tagx As Object
Dim repo As Object
Dim Element As HTMLButtonElement
i = 0
Set appIE = New InternetExplorerMedium
sURL = "http://myurl/blink/"
With appIE
.navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.READYSTATE <> 4
DoEvents
Loop
appIE.document.getElementById("Username").Value = "xxx"
appIE.document.getElementById("Pwd").Value = "xxxx"
Set tags = appIE.document.getElementsByTagName("Button")
tags(i).Click
Do While appIE.Busy Or appIE.READYSTATE <> 4
DoEvents
Loop
Application.Wait Now + TimeSerial(0, 0, 5)
Dim iFrm As MSHTML.HTMLElementCollection
'Dim iFrm As MSHTML.HTMLWindow2 ''' Wrong Object Defined
Dim HTMLdocc As HTMLDocument
Set iFrm = appIE.document.frames("MAIN").document.getElementById("topmenu")
Set iFrm2 = iFrm.getElementsByTagName("table")
x = 1
For Each Item In iFrm2
On Error Resume Next
If Item.ID = "table10" Then
iFrm3 = Item.getElementsByTagName("a")
iFrm3.Click
End If
On Error GoTo 0
Next
Application.Wait (Now + TimeValue("00:00:5"))
直到我的代码以上工作完全正常。当我进一步添加以下代码时,我在将 opn 定义为 MSHTML.HTMLWindow2 对象时面临类型不匹配错误。
'Dim opn As Object
Dim opn As MSHTML.HTMLElementCollection
Set opn = appIE.document.frames("MAIN").document.getElementsByTagName("table")