1

I tried to operate certain website by using vba, but I really can't figure out why my code doesn't work, could someone help me to check my code please ..

Web Page Source Code:

<td class="grid-cell purchaseOrderPUGrid-col4 cur center  cell-update " eno="edit" _col="10" field="selfVOService">EUR 0.00</td>
<input name="name1" class="name2" style="width: 156px;" onpaste="return false" oncontextmenu="return false" type="text">

My source code:

For Each oHTML_Element_2 In HTMLDoc.getElementsByTagName("input")
    If oHTML_Element_2.className = "name2" And oHTML_Element_2.Type = "text" Then
        oHTML_Element_2.Click
        oHTML_Element_2.txtamount.Value = "123"
        oHTML_Element_2.txtamount.Text = "123"
    End If
Next

1 Answer 1

1

You're almost there. You need to use just .value to set or retrieve the displayed value for the control object. So here is your working code:

For Each oHTML_Element_2 In HTMLDoc.getElementsByTagName("input")
    If oHTML_Element_2.className = "name2" And oHTML_Element_2.Type = "text" Then
        oHTML_Element_2.Value = 123
    End If
Next  

Also, you don't need to click the object in order to set some value. You're good as long as it's getting identified properly.

Sign up to request clarification or add additional context in comments.

2 Comments

many thanks! It works, but why I only just need .value there? also, how can I simulate press ENTER button on the website !?
Glad to help. You just need to use .value because there is no such method as .txtamount.Value or .txtamount.Text. Check this link for more info. Also check this link to see how you can press a button. P.S. Google is your friend... :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.