[英]Run time error 91 - IE Object
該代碼正常工作,但是當我嘗試關閉IE時,出現以下錯誤:
“運行時錯誤91”
Dim IE As Object
Dim shellWins As New ShellWindows
Dim IE_URL As String
Dim Row As Integer
Row = 2
For Each IE In shellWins
IE_URL = IE.LocationURL
If IE_URL <> vbNullString Then
Sheet1.Range("A" & Row) = IE_URL
row = Row + 1
End If
Next
Set shellWins = Nothing
Set IE = Nothing
IE.quit
新代碼:
Dim shellWins As New ShellWindows
Dim objIE As Object
Dim objIE_TabURL As String
Dim Rowcount As Long
Rowcount = 2
With objIE
Set objIE = CreateObject("InternetExplorer.Application")
For Each objIE In shellWins
objIE_TabURL = objIE.LocationURL
If objIE_TabURL <> vbNullString And InStr(objIE_TabURL,
"file://") = 0 Then
Rowcount = Rowcount + 1
sht2.Range("A" & Rowcount) = objIE_TabURL
End If
Next
objIE.Quit
End With
結束新代碼
我嘗試從IE會話中打開的選項卡中讀取URL,以將其導出到工作表中。
我很抱歉,但是我是VBA的新手:-(
IE
實際上在任何時候都沒有設置為Internet Explorer的實例,您正在將它用作循環中的對象變體。 循環結束后,變量將超出范圍,因此無法再以您希望的方式進行訪問。
如果要在檢索URL后關閉IE,請將代碼更改為:
For Each IE In shellWins
IE_URL = IE.LocationURL
If IE_URL <> vbNullString Then
Sheet1.Range("A" & Row) = IE_URL
row = Row + 1
IE.Quit '// Close IE here, while the variable is still in scope
End If
Next
請注意,由於VBA會自動為您管理內存,因此無需在例程末尾Set IE = Nothing
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.