0

I've written up some VBA code that looks up a laptop based on Service Tag and extracts the End of Warranty date. I have a list of about 200 Service Tags. I've noticed that after doing searches for about 10 of them, I get an error. I've labeled the line at which it eventually fails. Any ideas as to why it eventually fails? Do I have to increase the wait time?

On another note, is there a different way you would write the VBA code for it to run much more efficiently. I would think that I would be able to go through this list rather quickly, but then again I'm new to VBA.

Sub ServiceTagSearch2()

Dim ie As InternetExplorer
Dim webpage As HTMLDocument
Set ie = New InternetExplorer
Dim mtbl As String
Dim i As Integer
Dim cellRange As Range

ie.Visible = False
Set cellRange = Range("F3:F95")

For i = 1 To 93

url = cellRange.Cells(i, 1).Value

ie.navigate url

Application.Wait (Now + TimeSerial(0, 0, 7))

Set webpage = ie.document
mtbl = webpage.getElementById("warrantyExpiringLabel").innerText  <--------This is where I get the error

Cells(i + 2, 7) = mtbl

Set webpage = Nothing

Next i

End Sub

VBA code shown is for this worksheet

enter image description here

braX
  • 11,506
  • 5
  • 20
  • 33
  • It's possible the server is throttling your requests. When it fails does the loaded page look different (assuming you make IE visible) ? – Tim Williams Nov 14 '19 at 00:38
  • look at `ie.readystate` and `ie.busy` do a loop to not proceed until these are complete and not busy – Nathan_Sav Nov 14 '19 at 01:04
  • Also, look at is there a need to open the web page, or could you just send a request for the web page? https://stackoverflow.com/questions/3119207/sending-http-requests-with-vba-from-word – Nathan_Sav Nov 14 '19 at 01:06
  • @TimWilliams No, the page doesn't look any different. All I see is the page of the previous search. If you take a look at the image I provided, you will see that there is a missing entry for service tag c0pnbh2. This is when the error occurred. The page I would see is the search result for service tag gxnnbh2 (one before c0pnbh2). – Jose Ramirez Nov 14 '19 at 17:44

0 Answers0