gpt4 book ai didi

excel - 在IE窗口中填写表单: Press buttons and fill in text boxes

转载 作者:行者123 更新时间:2023-12-03 03:17:09 25 4
gpt4 key购买 nike

我正在尝试自动填写重复且耗时的 IE 站点。

我编写了启动 IE 的代码,使其对用户可见,并调暗了需要填写的变量。

我找到了文本框的 ID 和名称,但无法填写。

该网站是一个公司网站,因此我无法附加链接。

我可以附加我要填充的框和我要单击的按钮的 HTLM 代码。

文本框

<input name="ctl00$m$g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af$ctl00$grdLineItems$ctl02$txtDescription" 
type="text"
id="ctl00_m_g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af_ctl00_grdLineItems_ctl02_txtDescription"
class="txtDescription"
onkeydown="return (event.keyCode!=13);"
style="width:680px;margin-top:2px;margin-bottom:2px" />

点击按钮

<input type="submit"
name="ctl00$m$g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af$ctl00$ButtonAdd"
value="Add New Item"
id="ctl00_m_g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af_ctl00_ButtonAdd"
style="color:Black;background-color:White;font-size:Medium;font-weight:bold;width:150px;"/>

我尝试了不同的方法。我尝试按名称获取文本框,但文档命令出现错误。

我的代码

Sub Fill_in_eShipper()

Dim IE As Object Dim web_address As String
Dim number_of_elements As Integer
Dim MydataSet As Variant
Dim ObjCollection As Object

Windows("eshipper filler.xlsm").Activate

Set IE = CreateObject("InternetExplorer.Application")

web_address = Range("c2") Range("D2").Formula = "=ROWS(A1:A161)-1"
number_of_elements = Range("d2")

IE.navigate web_address
IE.Visible = True

While IE.Busy DoEvents 'Wait till IE is done loading Wend

'Number of elements to populate
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select

Range("D1").Select
ActiveCell.FormulaR1C1 = "=ROWS(RC[-3]:R[160]C[-3])-1"

IE.document.getelementsbyid("ctl00_m_g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af_ctl00_grdLineItems_ctl02_txtDescription").Value = Range("A2")
IE.document.All("ctl00$m$g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af$ctl00$ButtonAdd").Click

End Sub

最佳答案

尝试 - 将 Elements 更改为 Element,并继续使用 .getElementById 进行点击。

IE.document.getElementById("ctl00_m_g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af_ctl00_grdLineItems_ctl02_txtDescription").Value = Range("A2")
IE.document.getElementById("ctl00_m_g_8fbfd2b6_3945_4bee_9a3b_20cfc2c846af_ctl00_ButtonAdd").Click

关于excel - 在IE窗口中填写表单: Press buttons and fill in text boxes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52743508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com