How to fill web forms by vba if there dropdown list

Nemat2313

New Member
Joined
Jan 18, 2016
Messages
18
Hi Everyone

I have the code below, which navigates to a website, clicks on a link on that site to open page, and then attempts to fill forms. When reches to dropdown list (or combobox) with getting errors. It all works except for the last part of filling in the dropdown list. If someone could let me know how to modify that code that would be great. I'm not sure that I've choosed right html name of dropdown list.

Code:
Dim IE As ObjectSub Nalog()
   Dim objElement As Object
   Dim c As Integer
   Dim lastrow, i, j, m As Integer
   Dim UrlTochka As String
   Dim sht As Worksheet


    Set IE = CreateObject("InternetExplorer.Application")
    
    Set sht = ThisWorkbook.Worksheets("Data")
    lastrow = sht.Cells(sht.Rows.Count, "D").End(xlUp).Row
    UrlTochka = "https://service.nalog.ru/payment/payment.html"
    For j = 4 To lastrow
        Select Case j
            Case 20
               ActiveWindow.SmallScroll Down:=18
            Case 40
               ActiveWindow.SmallScroll Down:=18
            Case 80
               ActiveWindow.SmallScroll Down:=18
            Case 120
               ActiveWindow.SmallScroll Down:=18
            Case 160
               ActiveWindow.SmallScroll Down:=18
             End Select
    sht.Range(Cells(j, 1), Cells(j, 15)).Select
    With Selection.Interior
        .PatternColorIndex = xlAutomatic
        .Color = 6750105
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    With IE
                
      .Visible = True
      .navigate UrlTochka
      
      'wait until first page loads
   IEready




   With IE.document
      'text boxes
 
      .all("payerKind_fl").Click
      .all("btnNext").Click
      
   End With
   
   'wait until first page loads
      IEready
      
   With IE.document
      'text boxes
      
      .all("kbk").Value = sht.Cells(j, 7)
      .all("btnNext").Click
      
    End With
    
   
     IE.document.all("objectAddr").Value = sht.Cells(j, 41)
     IE.document.all("uni_kladr_1").Click
    
    'wait until first page loads
     IEready
     


     ' IE.Document.All("btn_ok").Click
    Dim HTMLdoc As MSHTML.HTMLDocument
    Dim htmlWindow As MSHTML.HTMLWindow2
    Set HTMLdoc = IE.document
    Set htmlWindow = HTMLdoc.frames(0)
    htmlWindow.document.all("btn_ok").Click
    
    IEready
     
     IE.document.all("btnNext").Click
     
     'First DropDown list selection first option code
     IE.document.getElementById("uni_select_22").selectedIndex = 1
    'After First DropDown selection appears second dropdown list, than select fist option in 2nd dropdown list
     IE.document.getElementById("uni_select_26").selectedIndex = 1
     
     IE.document.all("taxPeriodDate").Value = VBA.Format(sht.Cells(j, 10), "dd/mm/yyyy")
     IE.document.all("sum").Value = sht.Cells(j, 11)
    
    sht.Range(Cells(j, 1), Cells(j, 15)).Select
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    
    End With
    MsgBox sht.Cells(j, 4) & " has done. Click OK button to continue."
 Next j
  Set IE = Nothing
  
  

End Sub


Code:
Private Sub Wait(ByVal wSec As Long)    wSec = wSec + Timer
    Do While Timer < wSec
       DoEvents
    Loop
End Sub
'________
Private Sub IEready()
    Wait 2
    Do While IE.ReadyState <> 4
        Wait 2
    Loop
End Sub

1.First dropdown list html code
HTML:
<input id="uni_select_22" class="inp-std" autocomplete="off" type="text">
<a href="#" id="uni_select_21" tabindex="-1"></a>


2.Second dropdown list html code

HTML:
<input id="uni_select_26" class="inp-std" autocomplete="off" type="text">
<a href="#" id="uni_select_25" tabindex="-1"></a>



 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I found solution by below code:

Code:
html.all("paymentReason").selectedIndex = 1
     Set evt = IE.document.createEvent("HTMLEvents")
     evt.initEvent "change", True, False
     html.all("paymentReason").dispatchEvent evt


     html.all("taxPeriodKind").selectedIndex = 1
     Set evt = IE.document.createEvent("HTMLEvents")
     evt.initEvent "change", True, False
     html.all("taxPeriodKind").dispatchEvent evt
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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