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
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi, and welcome to the forum.

Try adding the code below after the end of your loop.
When the code stops, press F8 to step through the code.
Use Alt+TAB to flick between screens to see the form populate.

NB you will need to add cod to determine which ComboBox, OptionButton ITEM is selected

Rich (BB code):
   Stop
   
   'populate fields
   With IE.document
      'text boxes
      .forms("tax280").All("PAN").Value = "123"                   '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 type
   End With

ps
To check the correct webform names I used Google Chrome => right click => Inspect Element

[edit -pps]
use the full url to the webpage
Rich (BB code):
IE.navigate "https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp"
 
Last edited:
Upvote 0
Thanks a lot sir for your reply.

It worked !!

Need one more help sir. How to automatically enter the verification code into the text box, because every time the codes get changed.

Thank you again sir.
 
Upvote 0
If you mean the text generated by the, "captcha", then I don't think this can be done. (i.e., the text box under; "Type the characters you see in the picture below.")

Captcha's were invented to ensure that humans, not machines (i.e., code), were processing web pages.
 
Upvote 0
Atleast can we do that, a message gets displayed for the Captcha image & the user inputs the image into the text box it.
 
Upvote 0
I have modified your code slightly.

We have to wait for the initial webpage to load (ReadyState=4)
When you click the link, we have to wait for the INTERACTIVE webpage to load (ReadyState=3)

I prompt the user for the "Captcha" text and populate the webpage text box.
I have placed a STOP command before this happens if you want to step through the code (F8).
Optional - click the submit button
Wait for the interactive webpage to load (ReadyState=3)

See code snippet:

Rich (BB code):
  Stop
      strCaptcha = InputBox("Enter Captcha Text")
      .forms("tax280").All("captchaText").Value = strCaptcha
      .forms("tax280").All("Submit").Click
      
      'wait until interactive page loads - NB NOTE READY STATE NUMBR = 3
      Do Until .readystate = 3
         DoEvents
      Loop

The full amended code is below:
Rich (BB code):
Private Sub CommandButton1_Click()
   Dim IE As Object
   Dim objelement As Object
   Dim c As Integer
   Dim i
   Dim strCaptcha As String
   
   Set IE = CreateObject("InternetExplorer.Application")
   
   With IE
      .Visible = True
      .navigate "https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp"
      
      'wait until first page loads
      Do Until .readystate = 4
         DoEvents
      Loop
   
      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
         
         'wait until interactive page loads - NB NOTE READY STATE NUMBR = 3
         Do Until .readystate = 3
            DoEvents
         Loop
         Exit For
         End If
      Next i
   End With
   
   'populate fields
   With IE.document
      'text boxes
      .forms("tax280").All("PAN").Value = "123"                   '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 type
  Stop
      strCaptcha = InputBox("Enter Captcha Text")
      .forms("tax280").All("captchaText").Value = strCaptcha
      .forms("tax280").All("Submit").Click
      
      'wait until interactive page loads - NB NOTE READY STATE NUMBR = 3
      Do Until .readystate = 3
         DoEvents
      Loop


   End With
 
   Set IE = Nothing
End Sub
 
Upvote 0
I have tried to download the Captcha image, but, limited success. It downloads something, but, not in a recognisable image format.

Either I am missing something, or the webpage is blocking the Captcha download.

Here is the approach I used if anyone else wants to have a go.

Set two references, Tools=>References
Microsoft HTML Object Library (for the image variable)
Microsoft WinHttpServices version 5.1 (for the download function)

Edit the download path.

Rich (BB code):
'=======================================
'Requires Tools=>Reference
'Microsoft WinHttp Services version 5.1
'=======================================
Private Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    
    
Private Sub CommandButton1_Click()
   Dim IE As Object
   Dim objelement As Object
   Dim c As Integer
   Dim i
   Dim strCaptcha As String
   Dim strImageSource As String
   Dim img As HTMLHtmlElement 'Tools=>Reference=>Micrsoft Html Object Library
   
   Set IE = CreateObject("InternetExplorer.Application")
   
   With IE
      .Visible = True
      .navigate "https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp"
      
      'wait until first page loads
      Do Until .readystate = 4
         DoEvents
      Loop
   
      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
         
         'wait until interactive page loads - NB NOTE READY STATE NUMBR = 3
         Do Until .readystate = 3
            DoEvents
         Loop
         Exit For
         End If
      Next i
   End With
   
   'populate fields
   With IE.document
      'text boxes
      .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 type
  Stop
      'loop through the images on the webpage
      Set img = .forms("tax280").All("Captcha")
      URLDownloadToFile 0, img.href, "C:\temp\temp.png", 0, 0
      
      'ActiveSheet.Pictures.Insert ("C:\temp\temp.png")
   
   
      'strCaptcha = InputBox("Enter Captcha Text")
      '.forms("tax280").All("captchaText").Value = strCaptcha
      '.forms("tax280").All("Submit").Click
      
      'wait until interactive page loads - NB NOTE READY STATE NUMBR = 3
     ' Do Until .readystate = 3
     '    DoEvents
     ' Loop


   End With
 
   Set IE = Nothing
End Sub
 
Upvote 0
It's the website. When you download the Captcha image as a text file you get the message, "This page cannot be accessed directly."
 
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,148
Members
449,066
Latest member
Andyg666

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