reachmanoj27
New Member
- Joined
- Aug 31, 2016
- Messages
- 6
<code>I am pulling the data which is on table format from a website based on
from date, I am giving the date by using input box so that it goes and
sit in the form for from date box which is in website and search for
results but not unfortunately the date which i am giving is not sitting
in from date box, I am getting the blank results. Could you please help
on this? thank You in advance
Option Explicit
Sub extractTablesData()
Dim IE As Object, obj As Object
Dim myfromdate As String
Dim r As Integer, c As Integer, t As Integer
Dim elemCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
myfromdate = InputBox("Enter From date format YYYY-MM-DD")
With IE
.Visible = True
.navigate ("https://health-products.canada.ca/noc-ac/index-eng.jsp")
While IE.ReadyState <> 4
DoEvents
Wend
For Each obj In IE.Document.getElementsByName("nocFromdate")
If obj.innerText = myfromdate Then
obj.Selected = True
End If
Next obj
IE.Document.getElementsByName("action").Item.Click
Do While IE.busy: DoEvents: Loop
worksheets("Sheet1").Range("A:Z").ClearContents
Set elemCollection = IE.Document.getElementsByTagName("TABLE")
For t = 0 To (elemCollection.Length)
For r = 0 To (elemCollection(t).Rows.Length)
For c = 0 To (elemCollection(t).Rows(r).Cells.Length)
worksheets("Sheet1").Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText
Next c
Next r
Next t
End With
Set IE = Nothing
End Sub</code>
from date, I am giving the date by using input box so that it goes and
sit in the form for from date box which is in website and search for
results but not unfortunately the date which i am giving is not sitting
in from date box, I am getting the blank results. Could you please help
on this? thank You in advance
Option Explicit
Sub extractTablesData()
Dim IE As Object, obj As Object
Dim myfromdate As String
Dim r As Integer, c As Integer, t As Integer
Dim elemCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
myfromdate = InputBox("Enter From date format YYYY-MM-DD")
With IE
.Visible = True
.navigate ("https://health-products.canada.ca/noc-ac/index-eng.jsp")
While IE.ReadyState <> 4
DoEvents
Wend
For Each obj In IE.Document.getElementsByName("nocFromdate")
If obj.innerText = myfromdate Then
obj.Selected = True
End If
Next obj
IE.Document.getElementsByName("action").Item.Click
Do While IE.busy: DoEvents: Loop
worksheets("Sheet1").Range("A:Z").ClearContents
Set elemCollection = IE.Document.getElementsByTagName("TABLE")
For t = 0 To (elemCollection.Length)
For r = 0 To (elemCollection(t).Rows.Length)
For c = 0 To (elemCollection(t).Rows(r).Cells.Length)
worksheets("Sheet1").Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText
Next c
Next r
Next t
End With
Set IE = Nothing
End Sub</code>