PDA

View Full Version : Data from Web page / IE into Excel



scifilvr
04-04-2007, 11:30 AM
Hi All,

I've been using some code from here to get data into excel from
a webpage that requires a login and password. It works fine for a few
iterations, except I get the "Runtime Error 1004" after. I cant figure out why.

The main routine's for loop just loops through multiple pages to get data.
The subroutine GetAllTables is the one I'm having problems with. Error comes at rng.Value = c.innerText

Any help greatly, greatly appreciated.



Public nextrow As Integer
Public PartInc As Integer


Sub DataGather()


Dim EXP
Dim PageCount As Integer


Sheets("Part 2").Cells.Clear

Set EXP = CreateObject("InternetExplorer.application")
With EXP
.Visible = True
'put the webpage here
.Navigate ("<>") 'please insert webpage needing logging in
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
With .document.Forms(1)
.userid.Value = "****"
.pass.Value = "****"
.submit
End With
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
Set doc = EXP.document
PartInc = 1
PageCount = 1
GetAllTables doc

For Count = 200 To 2000 Step 200
.Navigate ("" & Count & "") 'Please insert webpage needing login here
Do While .Busy: DoEvents: Loop
Do While .ReadyState <> 4: DoEvents: Loop
'Set doc = EXP.document
GetAllTables doc
PageCount = PageCount + 1
If PageCount = 4 Then
PageCount = 0
nextrow = 0
PartInc = PartInc + 1
End If
Next Count

End With
End Sub

Sub GetAllTables(d)
For Each e In d.all
If e.nodename = "TABLE" Then
Set t = e
tabno = tabno + 1
nextrow = nextrow + 1
Set rng = ActiveWorkbook.Sheets("Part " & PartInc).Range("B" & nextrow)
rng.Offset(, -1) = "Table" & tabno
For Each r In t.Rows
For Each c In r.Cells
rng.Value = c.innerText
Set rng = rng.Offset(, 1)
I = I + 1
Next c
nextrow = nextrow + 1
Set rng = rng.Offset(1, -I)
I = 0
Next r
End If
Next e
End Sub