Mohammed Sahadat Alam
New Member
- Joined
- Mar 17, 2016
- Messages
- 1
Hi All,
Thanks to all Mr Excel for helping us with major & minor excel problems.
This is my first post in the forum and I will try my best to compose my problem in best possible way. Please consider me as beginner in VBA.
I am working on a project that needs web scraping to download a table from a website. The table is generated when a button " generate plan" is clicked which takes two dates from two textfields.
When the code is run in excel vba, it changes the value in To Date textfield to a DateAdd(adding a day to today date) which I want as per my requirement but when generate plan is clicked with the same code it generates table for only today which is 22/03/2016. To evaluate further I found when To date textfield is clicked it changes the value to today's date. I assume that my code runs correctly and populates the To date textfield with a dateadd value but it is not calculated when generate plan is clicked.
Now I kindly request if you can help me with this so I can progress with my project. I was wondering if textfield in form can be cleared and my date is populated ; so on clicking generate plan button it will take my value. Or any other ways will be appreciated.
Below is code so far structured based on examples found on www.
Thanks to all Mr Excel for helping us with major & minor excel problems.
This is my first post in the forum and I will try my best to compose my problem in best possible way. Please consider me as beginner in VBA.
I am working on a project that needs web scraping to download a table from a website. The table is generated when a button " generate plan" is clicked which takes two dates from two textfields.
When the code is run in excel vba, it changes the value in To Date textfield to a DateAdd(adding a day to today date) which I want as per my requirement but when generate plan is clicked with the same code it generates table for only today which is 22/03/2016. To evaluate further I found when To date textfield is clicked it changes the value to today's date. I assume that my code runs correctly and populates the To date textfield with a dateadd value but it is not calculated when generate plan is clicked.
Now I kindly request if you can help me with this so I can progress with my project. I was wondering if textfield in form can be cleared and my date is populated ; so on clicking generate plan button it will take my value. Or any other ways will be appreciated.
Below is code so far structured based on examples found on www.
Code:
Public Sub Login()
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim i As Long
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate ("http://Login.aspx") '
Do
DoEvents
Loop Until IE.READYSTATE = 4
Set AllHyperlinks = IE.Document.GetElementsByTagName("A")
For Each hyper_link In AllHyperlinks
If hyper_link.innertext = "here" Then
hyper_link.Click
Exit For
End If
Next
Do
DoEvents
Loop Until IE.READYSTATE = 3
Do
DoEvents
Loop Until IE.READYSTATE = 4
Set AllHyperlinks = IE.Document.GetElementsByTagName("A")
For Each hyper_link In AllHyperlinks
If hyper_link.innertext = "Transfer Plan" Then
hyper_link.Click
Exit For
End If
Next
Do
DoEvents
Loop Until IE.READYSTATE = 4
Do While IE.busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set objCollection = IE.Document.GetElementsByTagName("input")
i = 0
While i < objCollection.Length
[B][COLOR=#FF0000]'some code here to clear the form elements[/COLOR][/B]
If objCollection(i).Name = "ctl00$ContentAdmin$dtToDate" Then
objCollection(i).Value = DateAdd("d", 1, Date)
objCollection(i).Value = Format(objCollection(i).Value, "dd/MM/yyyy")
Else
If objCollection(i).Type = "submit" And _
objCollection(i).Name = "ctl00$ContentAdmin$btnSave" Then
Set objElement = objCollection(i)
End If
End If
i = i + 1
Wend
objElement.Click ' click button to search
' Wait while IE re-loading...
Do While IE.busy
Application.Wait DateAdd("s", 1, Now)
Loop
' Show IE
IE.Visible = True
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
Application.StatusBar = ""
End Sub