使用excel vba操作网页

时间:2022-11-19 22:53:42

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 ..

我试着用vba操作某些网站,但是我真的搞不懂为什么我的代码不能用,谁能帮我检查一下我的代码。

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 个解决方案

#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:

你差不多了。您需要使用.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  

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.

同样,您不需要单击对象来设置一些值。只要它被正确地识别出来,你就是好的。

#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:

你差不多了。您需要使用.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  

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.

同样,您不需要单击对象来设置一些值。只要它被正确地识别出来,你就是好的。