我創建了一個子來填充表單字段中的一個網站,從一個Excel工作簿Excel VBA填充I.E.導致I.E中的運行時錯誤11而不是9
子打開Internet Explorer中的新窗口,導航到Intranet站點,並填充表單字段從數據數據一個Excel工作簿
本小組使用Win7 Excel 2010和IE 9
當我使用IE瀏覽器的新版本,子打開Internet Explorer中的新窗口,並導航到Intranet網站,但無法填充表單字段 我收到以下錯誤從VBA:
運行時錯誤 '-2147417848(80010108)':
自動化錯誤
調用的對象已經與其客戶端斷開
這裏是我的代碼
Sub hOpenWsAndPopulate()
Dim ie As Object
Dim frm As Variant
Dim element As Variant
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "www.mywebsite.com"
While ie.readyState <> 4: DoEvents: Wend
' try to get form by ID
Set frm = ie.document.getElementById("incidentTicket_Form")
' try to get form by tag name and index.
' Item(0) = 1st form
' Item(1) = 2nd form
' Item(2) = 3rd form, etc.
If frm Is Nothing Then Set frm = ie.document.getElementsByTagName("form").Item(0)
If frm Is Nothing Then
MsgBox "Form not found"
ie.Quit
Set ie = Nothing
Else
ie.Visible = True
For Each element In frm.elements
On Error Resume Next
Select Case element.Name
' Input Classification
Case "strClassificationName": element.Value = Sheets("OUT-Class").Range("Classification")
' Input Short Description
Case "txtShortDescription": element.Value = Sheets("OUT-SD").Range("SD_Output")
' Input Long Description
Case "txtLongDescription": element.Value = Sheets("OUT-LD").Range("LD_Output")
' Input CC
Case "strCCString": element.Value = Sheets("OUT-CC").Range("CcBa")
End Select
Next
End If
End Sub
我試過很多改變我的代碼(見下文),但沒有任何工程
Sub zzzOpenWsAndPopulate()
Dim objIE As InternetExplorer
Dim htmlDoc As HTMLDocument
Dim htmlFrame As HTMLFrameElement
Dim frame As HTMLIFrame
Dim htmlElement As HTMLDTElement
Dim myDoc As Object
Dim frm As Variant
Dim element As Variant
' Set the variables
Set objIE = New InternetExplorer
' Make the browser visible and navigate
With objIE
.Visible = True
.navigate "www.mywebsite.com"
End With
hWaitForInternetToLoad objIE
Set frm = objIE.document.getElementById("incidentTicket_Form")
If frm Is Nothing Then Set frm = ie.document.getElementsByTagName("form").Item(0)
If frm Is Nothing Then
MsgBox "Form not found"
ie.Quit
Set ie = Nothing
Else
objIE.Visible = True
For Each element In frm.elements
On Error Resume Next
Select Case element.Name
' Input Classification
Case "strClassificationName": element.Value = Sheets("OUT-Class").Range("Classification")
' Input Short Description
Case "txtShortDescription": element.Value = Sheets("OUT-SD").Range("SD_Output")
' Input Long Description
Case "txtLongDescription": element.Value = Sheets("OUT-LD").Range("LD_Output")
' Input CC
Case "strCCString": element.Value = Sheets("OUT-CC").Range("CcBa")
End Select
Next
End If
End Sub
是否有關於IE的東西10,11等與I.E不同。 9?
有沒有辦法強制開啓舊版本的I.E. (瀏覽器模式9)
有什麼建議嗎?