Excel VBA automatic fill and submit web forms from excel data

Nemat2313

New Member
Joined
Jan 18, 2016
Messages
18
Hi,

My below code works find with F8 key, but run key doesn't fill the web form. I tried so many time readyState function but still doesn't work. Could anyone knows whats the problem there.

Please watch this video to better understand the problem.
https://youtu.be/zxL5GlhG0iA


Code:
Sub Sprint()
   Dim IE As Object
   Dim objelement As Object
   Dim c As Integer
   Dim LastRow, i, j As Integer
  
   Set IE = CreateObject("InternetExplorer.Application")
   
   With IE
      .Visible = True
      .navigate "https://website url here #"
      
      'wait until first page loads
      Do Until .readyState = 4
        DoEvents
      Loop
   
      On Error Resume Next

Set sht = ThisWorkbook.Worksheets("Data")
LastRow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row
For j = 4 To LastRow
       
    i = 112
             
         If IE.document.all.Item(i).innertext = "ÔÍÑ (ãîñ. ïîøëèíà)" Then
         IE.document.all.Item(i).Click
         
         End If
    
   IE.Visible = True
   While IE.Busy
   DoEvents  'wait until IE is done loading page.
   Wend
         
   'populate fields
   
   With IE.document
      'text boxes
      
      .all("fio").Value = sht.Cells(j, 1) 
      .all("contact").Value = sht.Cells(j, 2)
      .all("payer_address").Value = sht.Cells(j, 3) 
      .all("inn_from").Value = sht.Cells(j, 4) '"771562265931"
      .all("inn").Value = sht.Cells(j, 5) '"7726062105"
      .all("account").Value = sht.Cells(j, 6) '"45914000"
      .all("purpose").Value = sht.Cells(j, 7) 
      .all("comment").Value = sht.Cells(j, 8) '"02.04.2016"
      .all("sum").Value = sht.Cells(j, 10) '"1000"
      .all("get_total_sum").Click
      '.all("now_pay").Click
    
    End With
        Set IE = Nothing

    Next j
 End With
End Sub
 
You haven't changed code that opens form web page.

Try below code to Login first, if it works fine you can write next code to fill the form.

Code:
Sub Login()
    Dim objelement As Object
   Dim c As Integer
   Dim LastRow, i, j As Integer
   
  
  
   Set ie = CreateObject("InternetExplorer.Application")
   
With ie
      .Visible = True
      .navigate "https://www.njmmis.com/mevs.aspx"
      
      'wait until first page loads
   On Error Resume Next
    Do
        If ie.ReadyState = 4 Then
            ie.Visible = True
            Exit Do
        Else
            DoEvents
        End If
    Loop
  

 'Login code here
                With ie.document
                      .all("txtUserName").Value = "enter here UserName"       'Sheet1.Range("B2").Value
                       .all("txtPassword").Value = "enter your Password"         'Sheet1.Range("B3").Value
                      .all("btnSubmit").Click
                   
                End With
   

End With
 
    Do While ie.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop
 

    ie.Visible = True
 

    Set ie = Nothing
    End Sub
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Thanks Ombir, just to ask you something here if you can help

1. After clicking on Submit button say it opens a new web page
2. How to make the VBA read Elements name/id/tag from it, as New IE page is not set as the first one (Set IE = CreateObject("InternetExplorer.Application"))

here is some issues I am facing in defining the next IE page and reading the Elements from it to fill the form.

Kindly suggest
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,059
Members
452,542
Latest member
Bricklin

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