0

I am trying to extract data from a password protected website using a code online and I keep receiving a run time error - '2137317848....'

. The error begins on the line that contains:

Do Until ieApp.ReadyState = READYSTATE_COMPLETE

I am unsure how to fix this problem.

Sub Getdata()
MyString = ActiveCell.Value
Application.Calculation = xlCalculationManual

Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Dim clip As DataObject

'create a new instance of ie
Set ieApp = New InternetExplorer

'you don’t need this, but it’s good for debugging
ieApp.Visible = True

'assume we’re not logged in and just go directly to the login page
ieApp.navigate MyString
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

Set ieDoc = ieApp.Document

'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.login.Value = "myuserid"
.Password.Value = "pass"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

'now that we’re in, go to the page we want
ieApp.navigate MyString
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop

'get the table based on the table’s id
Set ieDoc = ieApp.Document
Set ieTable = ieDoc.getitembyClass.Item("primary-link")

'copy the tables html to the clipboard and paste to teh sheet
If Not ieTable Is Nothing Then
Set clip = New DataObject
clip.SetText "" & ieTable.outerHTML & ""
clip.PutInClipboard
Sheet1.Select
Sheet1.Range("A1").Select
Sheet1.PasteSpecial "Unicode Text"
End If

'close 'er up
ieApp.Quit
Set ieApp = Nothing

End Sub

I am hoping to grab the data by its class id so if that also doesn't look correct please let me know!

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • try with internetexplorer medium and check that you are using a valid url/ – QHarr Jul 16 '19 at 18:15
  • The error shows in which line? As you have many lines of `Do Until ieApp.ReadyState = READYSTATE_COMPLETE` in the code. We have no idea of the address of the website you use, so we're not sure if you put a valid address in the ActiveCell. You could first try to login the website in IE without VBA automation to see if it works. I tested in my side with a valid url and the code works. And If you want to get data by its class, you could use `getElementsByClassName`. – Yu Zhou Jul 17 '19 at 06:36
  • the very first instance of Do Until ieApp.ReadyState = READYSTATE_COMPLETE I cannot get past it unfortunately, also I have tried Internet medium and still get the same error. – Katie Kelly Jul 17 '19 at 14:13
  • Is your url valid? And you could try the late bind to see if it works. Please try the accepted answer in [this thread](https://stackoverflow.com/questions/51263106/vba-internet-explorer-automation-error). For more information, please check [this article](http://www.vba-market.com/2017/03/04/the-object-invoked-has-disconnected-from-its-clients/). It provides many solutions of this issue. – Yu Zhou Jul 18 '19 at 08:50

0 Answers0