使用excel vba来操作网页
我试图通过使用vba操作某些网站,但我真的不知道为什么我的代码不起作用,有人可以帮我检查我的代码,请..
网页源代码:
<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">
我的源代码:
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
你快到了。 您只需使用.value
来设置或检索控制对象的显示值。 所以这里是你的工作代码:
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
另外,您不需要单击该对象以设置某个值。 只要正确识别,你就很好。