代碼工作正常,但是當我試圖關閉IE瀏覽器,我得到以下錯誤:運行時錯誤91 - IE對象
"Run Time Error 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
NEW CODE:
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
END NEW CODE
我嘗試從IE會話中打開的標籤中讀取URL以將其導出到工作表中。
我很抱歉,但我在VBA新手:-(
您在退出之前設置IE = Nothing',因此您殺死了IE對象,之後您無法再訪問它。在設置'IE = Nothing'之前退出應該工作。 –
@Peh實際上,「IE」甚至沒有設置爲循環之外的Internet Explorer實例,因此無法工作。 –
@MacroMan你是完全正確的。只能看到與錯誤消息匹配的最終問題。 –