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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try to change
Do Until .readyState = 4
DoEvents
Loop

and

While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend


to

Do While IE.Busy Or IE.ReadyState <> 4: DoEvents: Loop

Bye
 
Upvote 0
Try this:

Code:
Dim IE as Object
Sub Sprint()
   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
   Ieready
      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
   
   Ieready
         
   '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
Private Sub Wait(ByVal wSec As Long)
    wSec = wSec + Timer
    Do While Timer < wSec
       DoEvents
    Loop
End Sub
Private Sub Ieready()
    Wait 5
    Do While IE.readyState <> 4
        Wait 5
    Loop
End Sub
 
Upvote 0
Thanks a lot. Code works as I want. Just I've changed Wait 5 into Wait 1 to increase speed.
Do While IE.Busy Or IE.ReadyState <> 4: DoEvents: Loop doesn't fill forms. Thank you, too!
 
Upvote 0
Dear Ombir

One more question. After filling form appears web messages to accept payment by click OK button. What we should to add to click the button. In excel has has Application.DisplayAlerts = False function. is there any function like this on the web?

Regards,
Nemat
 
Upvote 0
I can only be able to tell after checking HTML code of the website you're navigating. What is URL name and what exactly you're trying to do ?
 
Upvote 0
Ombir. When above code riches .all("now_pay").click will appears popUP menu with OK button. I have to manually click to continue each time. Below link you can find print screen of web site. Website url could access only with our companies computers. I couldn't find to add attachments here. So I could send you HTML codes by mail.

1. Video link https://drive.google.com/open?id=0B8mEUFOrXM4taDlscm14QlVBUGFDRmMtNWZ6VXoxUjlaOWRV

2. Gif file https://drive.google.com/open?id=0B8mEUFOrXM4tV0piT1RKN2hSM0JZNGZpSlRJbWtEb1V0b1Zj
open
 
Upvote 0
I tried so many internet links about web popup massage, that link also tried. I think i couldn't put that codes in right places or with correct names. Could you please show me where i have to write that codes.
Tomorrow i will linked HTML codes for you from companies computer.
 
Upvote 0
Ombir Here is HTML code link https://drive.google.com/open?id=0B8mEUFOrXM4tTkNaSG9NVUlvNlhlbEhiUXZHaVlwZFBjd1U0
On the web page when click below link opens form, that form opens not a new Window, so that HTML code also not changes.
HTML:
ФНС (гос. пошлина)

ФНС (гос. пошлина)


Submit "Отправить" button HTML code:

<input class="submit submit_save" id="now_pay" value="Отправить" type="submit">

When confirm web message appears HTML code debugger:
HTML:
if (confirm("Сумма платежа: "+$('#total_sum').val()+" руб.\nСумма, отправляемая поставщику: "+$('#sum').val()+" руб.\n\nПродолжить?")) {
                        return true;
                    }
                } else {
if (confirm("Сумма платежа: "+$('#total_sum').val()+" руб.\nСумма, отправляемая поставщику: "+$('#sum').val()+" руб.\n\nПродолжить?")) {
return true;
}
} else {
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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