VBA Code for filling up the online form

sknilesh1

New Member
Joined
Aug 20, 2013
Messages
14
Hi,

I have written the VBA code to access a certain webpage & fill up the form there.

First of all I have opened a site, then clicked on the link given there.

But I am not able to fill in the inputs there.

Please sugget me what to do .....

My VBA code is as follows :
Private Sub CommandButton1_Click()
Dim IE As Object
Dim objelement As Object
Dim c As Integer
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp"
While IE.busy
DoEvents
Wend
IE.Visible = True
On Error Resume Next

For i = 1 To IE.document.all.Length
If IE.document.all.Item(i).innertext = "CHALLAN NO./ITNS 280" Then
IE.document.all.Item(i).Click

Exit For
End If
Next i
Set IE = Nothing
End Sub
 
Sir,
Thanks for your time & knowledge.

The last thing remaining in my project is to copy the contents of final web page to the excel.:)
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
To do so will need to identify the "names" or "id's" of the controls to access their contents.

I use Google Chrome. I right click the control and select Inspect Element. This allows me to inspect the source code to get the info I need.

Other browser have add-ons for this.
Google "browser name" Inspect Element.

In the code snippet below, we identified the name of the form, and the control:

Rich (BB code):
      .forms("tax280").All("PAN").Value = "123"                   'permanent account number
      .forms("tax280").All("Add_Line1").Value = "a1"              'address line 1

In your case you will be assigning the values to a variable or cell.

Rich (BB code):
      myPan=.forms("tax280").All("PAN").Value                   'permanent account number
      Range("A1").value = .forms("tax280").All("Add_Line1").Value             'address line 1
 
Upvote 0
Sir,

Needed one further help on this.
Can we copy/download & display that image in the excel it self & then enter that code from there in our input box.

If this could happen then it will be very usefull for me. Becoz what now is happning is that I to press Alt + Enter & then enter the captcha into the input box.
 
Upvote 0
No we can't. As I said in post #10, the webpage/file containing the Captcha image is private and cannot be accessed.
 
Upvote 0
I have used the Above code in VBA as well as vb 6.0 but the code works in Debug Mode when i place the Breakpoint on the line containing the following code.And when i dont Place the Breakpoint that is if i dont debug it then the Form is not Filled with the Values..Stuck between this..And when i place the Error handler i get the Following error ...

Object Variable and with block Variable not set..

With IE.document
.forms("tax280").All("PAN").Value = "1234567890" 'permanent account number .forms("tax280").All("Add_Line1").Value = "a1" 'address line 1 .forms("tax280").All("Add_Line2").Value = "a2" 'address line 2 .forms("tax280").All("Add_Line3").Value = "a3" 'address line 3 .forms("tax280").All("Add_Line4").Value = "a4" 'address line 4 .forms("tax280").All("Add_Line5").Value = "a5" 'address line 5 .forms("tax280").All("Add_PIN").Value = "111" 'pin number .forms("tax280").All("Add_EMAIL").Value = "abc@hotmail.com" 'eMail .forms("tax280").All("Add_MOBILE").Value = "123456789" 'mobile number 'combo boxes - EDIT ITEM NUMBERS .forms("tax280").All("AssessYear").Item(2).Selected = True 'assessment year .forms("tax280").All("Add_State").Item(3).Selected = True 'state .forms("tax280").All("BankName_c").Item(3).Selected = True 'state 'option buttons - EDIT ITEM NUMBERS .forms("tax280").All("MajorHead").Item(1).Checked = True 'tax applicable .forms("tax280").All("MinorHead").Item(1).Checked = True 'tax t</pre></pre>
 
Upvote 0
Hi Naina, and welcome to the forum.

As it has been several months since I looked at this thread I copied the code from post#6 for testing. The code worked as expected. So I cannot recreate the error you speak of, I'm afraid.

A quick Google search does indicate issues surrounding early/late binding of object(IE) variables using VB.Net, but, I cannot find any issues relating to VB6.

Sorry I couldn't be more helpful.
Bertie
 
Upvote 0
Hi Mr. Bertie,

I have found your code very helpful for me as well as I am trying a similar form filling process. But in this form that I am filling online there are validation checks which gets activated after a tab or enter key event so that the following textboxes get automatically filled through the validation process of the form. Say for example there is a Date of Birth Field which after entering does a validation and automatically calculates the age of the person and fills up the next corresponding textboxes.

So when I enter the code for the date field through VB 6 code how do I activate the TAB or ENTER Key Event. Below is the code.

.Forms("OnlineForm").All("applicant_dob").Value = "31/10/1972"

After entering this value, how do I get it to run the validation check.
 
Upvote 0
Spereira
Hi, and welcome to the forum.

All web form controls, should have, a name or id attribute. To manipulate that control you need to find this.
In your browser, right click the control and select Inspect Element. Text boxes should have a name attribute, something like:
Rich (BB code):
Submit: <input type="text" name="submit" >

In your code you can target this control as in previous examples in this thread, or use GetElementsByName method and click it..
Rich (BB code):
ie.document.GetElementsByName("submit").Click

You may have to pause your code until the server side validation script catches up; use:
Rich (BB code):
Do While ie.Busy
   DoEvents
Loop
 
Upvote 0
Hi Bertie,

Thanks for the response. I've checked on what you had mentioned but I am assuming that this would work if I want to click on a command button. But this is not the case. I tried using the same to send a click onto the next textbox but eventually nothing happens. Actually when the textbox loses focus and moves to the next textbox it runs a particular function. It's like in your thread when you enter the PAN number and then you fill values the next textbox. It allows you to fill in less than 10 digits. But physically if you press enter in the PAN textbox, it invokes a validation check stating that the PAN should not be less than 10 digits.

.forms("tax280").All("PAN").Value = "123" 'permanent account number

This is what I want to do here after filling in the date of birth value I need to send a tab key or an enter key for the internal validation check to get activated.
 
Upvote 0
Hi Berite,

I managed to get it done by first setting the focus on the texbox, then filling in the value and finally using SENDKEYS with an Enter command which then triggers the function after it loses focus from the first textbox.

Thanks for your help Bertie. I may need some more of your expertise advise again.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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