Hello, I have following issue:
I try to pull some data from html table using a code below. Just to explain - It is web where I need to put some values into forms and press enter to generate a html table.
My code works just fine BUT only when I go to "View Code" and run the macro from there. When I run the macro via button or from Developer tab, it DOES NOT work well. Basically what it does is it intputs only the first row from html table instead of its full content (cca 14 rows). What really confuses me is, that when I run the macro from "View Code" for the first time a then run again via button suddenly it works just fine. This happens till I close the whole workbook, when I open it again I have to run the macro from the "View Code" again...
My code is located in Module1. Is that an issue? Do you have any idea what am I doing wrong.
Thanks
My code:
Sub Download()
Dim IE As Object
Dim hTable As Object
Dim hBody As Object
Dim hTR As Object
Dim htD As Object
Dim tb As Object
Dim tr As Object
Dim td As Object
Start = Day(Date - 20) & "." & Month(Date - 20) & "." & Year(Date - 20)
Ending = Day(Date) & "." & Month(Date) & "." & Year(Date)
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate " 'Web site from which I am dowloading data' "
Do Until IE.readyState = 4
Loop
IE.document.all("txtDateFrom").Value = Start
IE.document.all("txtDateTo").Value = Ending
IE.document.all("txtDateTo").Select
SendKeys "{ENTER}", True
SendKeys "{NUMLOCK}", True
Application.Wait (Now + TimeValue("00:00:01"))
Set hTable = IE.document.getElementsByTagName("table")
For Each tb In hTable
Set hTR = IE.document.getElementsByTagName("tr")
For Each tr In hTR
Set htD = tr.getElementsByTagName("td")
y = 1
For Each td In htD
Cells(x, y) = td.innerText
y = y + 1
Next td
x = x + 1
Next tr
Exit For
Next tb
IE.Quit
End Sub
Bookmarks