IE.Document.getElementsByName(“name”)。Value =“Value”not working [VBA]

问题描述:

当我尝试这样做时,它会在我身上抛出一些错误,这取决于我的代码的其他位,例如方法不与该对象或未指定的错误关联。IE.Document.getElementsByName(“name”)。Value =“Value”not working [VBA]

我想下去的Excel单元格的字符串列表,并使用Web窗体来搜索这些字符串。帮帮我!

我的代码目前看起来是这样的:

Sub YSF_automation() 
    Application.ScreenUpdating = False 

    Set IE = CreateObject("InternetExplorer.Application") 
    IE.Visible = True 
    IE.Navigate "URL" 

    While IE.Busy 
     DoEvents 
    Wend 

    IE.Document.getElementsByName("ElementName")(0).Value = "test" 

End Sub 
+0

没有看到任何你的代码,这是最好的,我有...修改代码,'IE.Document .getElementsByName(“name”)(0).Value =“Value”' – user1

+0

IE.Document.getElementsByName(“name”)返回不是单个元素的元素集合,因此您无法设置它的值。试试@ user1建议的内容。请记住,集合中的索引将从0开始,因此请按照您的要求进行更改。 – sktneer

+0

这是我正在尝试写入的文本框的HTML:。 – YaYaYaYaYaYa

尝试以下

Option Explicit 

Dim IE as Object 

Sub YSF_automation() 
    Application.ScreenUpdating = False 

Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
IE.Navigate "URL" 

While IE.Busy 
    DoEvents 
Wend 

set document = IE.document 
with document 
    .getElementsByName("ElementName")(0).value="test" 
end with 
End Sub