Clear/Erase Web Form Element Contents using Excel VBA for web scraping

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.

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
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,225,051
Messages
6,182,571
Members
453,126
Latest member
NigelExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top