这不是我第一次提到这个......但是我是vba的新手,需要帮助... 我在使用vba excel填写网页框中的值时遇到了麻烦。
该框的源代码是
<input
name="MultiRenameTable_OR:wt.epm.EPMDocument:3053059700_NEWNAME_JSID"
class="enabledfield"
id="MultiRenameTable_OR:wt.epm.EPMDocument:3053059700_NEWNAME_JSID"
style="WIDTH:98% onblur="setJSAttributeValue(this,'NEWNAME_JSID','MultiRenameTable', 'epmdoc_09876889_u46_drw',undefined)" type="text" size="25" ?=""
trlId="MultiRenameTable_epmdoc_09876889_u46_drw_NEWNAME_JSID"></input>
我写的代码是
Sub xx()
Dim ie As Object
Dim doc As HTMLDocument
Dim lo As IHTMLElementCollection
Dim l As IHTMLElement
Set ie = CreateObject("internetexplorer.application")
ie.navigate "mysiteurl"
ie.Visible = True
Do While ie.Busy: DoEvents: Loop
Do While ie.readyState <> 4: DoEvents: Loop
Set doc = ie.document
doc.getElementById("MultiRenameTable_OR:wt.epm.EPMDocument3053059700_NEWNAME_JSID").Value = "xyz"
End Sub
它没有设定值。 此外,我不能使用&#34; name&#34;,&#34; ID&#34;,&#34; trlID&#34;,&#34; onblur&#34;因为每次启动IE时他们都会不断变化 请帮帮我。
答案 0 :(得分:1)
我猜测setJSAttributeValue
该名称将始终包含子字符串&#34; NEWNAME_JSID&#34;。只需获取所有输入元素,然后遍历它们,在名称中查找它:
Sub xx()
Dim ie As Object
Dim doc As HTMLDocument
Dim lo As IHTMLElementCollection
Dim l As IHTMLElement
Set ie = CreateObject("internetexplorer.application")
ie.navigate "mysiteurl"
ie.Visible = True
Do While ie.Busy: DoEvents: Loop
Do While ie.readyState <> 4: DoEvents: Loop
Set doc = ie.document
Set lo = doc.getElementsByTagName("input")
For Each l In lo
If l.Name Like "*NEWNAME_JSID*" Then
'Do whatever.
Exit For
End If
Next l
End Sub