0
아래 코드는 처음 실행될 때 작동하지만 후속 실행에서는 종종 실패합니다. 실패한 행은 아래에 설명되어 있습니다. SHDocVw.ShellWindows를 반복하면 문제가 발생하고 다시 실행하기 전에 정리해야한다고 생각합니다. 문제를 복제하려면 IE에서 Google을 연 다음이 절차를 반복하십시오. 어떤 도움을 주셔서 감사합니다. 정확한 오류는 HRESULT : 0x800A01B6의 예외입니다. (이것은이 설정되어있는 경우 실제로 여러 번 IE_test 재사용 할 더 복잡한 코드의 단순화 된 버전입니다 있습니다.)때로는 .Document.Body.InnerHtml을 가져올 수 없습니다.
Public IE_test As SHDocVw.InternetExplorer
Sub TestIE()
Dim shellWindows_3 As New SHDocVw.ShellWindows()
Dim htmlDoc As String
Dim link1 = "google.com"
If IsNothing(IE_test) = True Then
For Each ie_x As SHDocVw.InternetExplorer In shellWindows_3
If ie_x.LocationURL.Contains(link1) Then 'find the google instance
IE_test = ie_x
End If
Next
End If
With IE_test
.Visible = True
htmlDoc = .Document.Body.InnerHtml 'Fails here on second run
.Quit()
End With
IE_test = Nothing
MsgBox(Len(htmlDoc))
End Sub