2017-10-18 337 views
0

當我嘗試這樣做時,它會在我身上拋出一些錯誤,這取決於我的代碼的其他位,例如方法不與該對象或未指定的錯誤關聯。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

回答

0

嘗試以下

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 
相關問題