0

I am having trouble figuring out why the Internet Explorer windows are visible even though I set .Visible = False, and why they don't close with IE.Quit and Set IE = Nothing.

I want to pull tracking numbers and scrape USPS by concatenating them onto the URL. The links work but the Internet Explorer Windows are visible and they don't close.

Dim newSheet As Worksheet
Set newSheet = Sheets.Add

Worksheets("AAASWOSPOLevel_crosstab").Activate
Dim i As Integer
Dim usps As Integer
Dim ups As Integer
Dim fedex As Integer
Dim dhl As Integer
Dim ontrac As Integer

i = 2
usps = 2
ups = 2
fedex = 2
dhl = 2
ontrac = 2

newSheet.Cells(i - 1, 1) = "USPS"
newSheet.Cells(i - 1, 3) = "UPS"
newSheet.Cells(i - 1, 5) = "FedEx"
newSheet.Cells(i - 1, 7) = "DHL"
newSheet.Cells(i - 1, 9) = "OnTrac"

newSheet.Activate
newSheet.Range("A:P").NumberFormat = "@"


While Not IsEmpty(Worksheets("AAASWOSPOLevel_crosstab").Cells(i, 15).Value)
    If Worksheets("AAASWOSPOLevel_crosstab").Cells(i, 15).Value = "USPS" Then
        newSheet.Cells(usps, 1) = Replace(Worksheets("AAASWOSPOLevel_crosstab").Cells(i, 13), """", "")

        Dim IE As Object
        Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
        With IE
            .Navigate "https://tools.usps.com/go/TrackConfirmAction?tLabels=" & Replace(Worksheets("AAASWOSPOLevel_crosstab").Cells(i, 13), """", "")
            .Visible = False
        End With

        While IE.ReadyState <> READYSTATE_COMPLETE
            DoEvents
        Wend

        IE.Quit
        Set IE = Nothing

        usps = usps + 1

        If usps = 7 Then Exit Sub
End If
Wend
user5932842
  • 67
  • 1
  • 7
  • Don't worry about `visible=false` and `ie=nothing` for now. You need to get `ie.quit` figured out. What if you insert a breakline right after the `Quit` statement and check the `ie` variable. Is it still assigned or is it already `Nothing` prematurely? Also perhaps stepping through the code with F8 will help find the issue. See more on that here: Chip Pearson's [Debugging VBA](https://stackoverflow.com/a/50189159/8112776) – ashleedawg Jul 27 '18 at 01:51
  • I guess there is `On Error Resume Next` somewhere before the posted part of the code? If so - remove it. Also make a check: if `TypeName(IE)` returns `"Object"` then it means that IE object has been disconnected, and you need to find that IE window looping through all explorer windows (identifying e. g. by title or URL), and quit it. – omegastripes Jul 27 '18 at 02:01
  • Sometimes IE not Quit because of the behavior of the website itself such as taking to long to response for clean up and you also can find IE still running in background. If this happened I would suggest you to force kill the IE process in background. – user2851376 Jul 27 '18 at 05:30

0 Answers0