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
Jordan
  • 4,424
  • 2
  • 18
  • 32

1 Answers1

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.

ManishChristian
  • 3,759
  • 3
  • 22
  • 50
  • many thanks! It works, but why I only just need `.value` there? also, how can I simulate press ENTER button on the website !? – Jimmy Huang Jan 25 '17 at 16:02
  • Glad to help. You just need to use `.value` because there is no such method as `.txtamount.Value` or `.txtamount.Text`. Check this [link](https://msdn.microsoft.com/en-us/library/ms535841(v=vs.85).aspx) for more info. Also check this [link](http://stackoverflow.com/questions/17179872/i-need-to-find-and-press-a-button-on-a-webpage-using-vba) to see how you can press a button. P.S. Google is your friend... :) – ManishChristian Jan 25 '17 at 16:15