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.
1.First dropdown list html code
2.Second dropdown list html code
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: