我想在网页文本框中添加值,但会出现对象错误。我不能提供网址,因为它不会在办公室外工作。
下面的html代码:文本框:
<input type="text" size="40" name="agent" id="go" value="">
搜索:
<button type="submit">Submit</button>
VBA:
Sub login_page()
Dim ieApp As SHDocVw.InternetExplorer
Dim iedoc As MSHTML.HTMLDocument
IEApp.Visible = True
Set ieApp = New SHDocVw.InternetExplorer
ieApp.Visible = True
ieApp.navigate "http:/Login"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Set iedoc = ieApp.document
with iedoc.forms(0)
.user.Value = "id"
.Password.Value = "Pass"
.submit
End With
ieApp.navigate "http:action=view"
Do While ieApp.Busy: DoEvents: Loop
'Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
ieApp.navigate "http:action=run"
Do While ieApp.Busy: DoEvents: Loop
ieApp.navigate "http:Report?"
action=run&category=interfaces&template=base%2Frouterprotocols§ion=5"
Do While ieApp.Busy: DoEvents: Loop
ieApp.document.parentWindow.execScript "window.location='Go?action=agent'"
End Sub
有一个id所以使用它
ieApp.document.getElementById("go")
前面的代码
Dim ieApp As InternetExplorer
Set ieApp = New InternetExplorer
With ieApp
.Visible = True
.Navigate2 "URL"
While .Busy Or .readyState < 4: DoEvents: Wend
.document.getElementById("go").value = "xyz"
End With
让我来帮助你。
Dim ie As New InternetExplorer
Dim elemnts As Object
Dim elem As Object
ie.Navigate url
Do While ie.ReadyState = 4: DoEvents: Loop 'Do While.
Do Until ie.ReadyState >= 3: DoEvents: Call aceitaAlerta(False): Loop 'Do Until
Set ELEMENTS = ie.Document.all
For Each elem In ELEMENTS
on error goto NextOne
If elem.name = "agente" And elem.id = "go" Then
elem.Value = "NEWVALUE"
elem.innerText = "NEWVALUE"
Exit For
End If
NextOne:
on error goto 0
Next elem