Nol*_*884 5 excel internet-explorer vba excel-vba inputbox
我读了很多关于我的问题的答案,但不知怎的,如果我试图"模仿"我看到的东西,我仍然无法做我需要的东西.
问题非常简单:在打开的IE页面上填写输入框.
结果:代码卡在行上并getelementbyid
显示运行时错误424(需要对象).
Private Sub AddInfoFromIntranet()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
Application.SendKeys "{ESC}" ' I need this to ignore a prompt
With ie
.Visible = True
.navigate "{here goes the address of my website}"
Do Until Not .Busy And .readyState = 4
DoEvents
Loop
.document.getelementbyid("Nachnamevalue").Value = "{here goes whar I want to insert}"
End With
Set ie = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)
Internet Explorer库是自然导入的(否则"internetexplorer.application"将不起作用.
我很肯定我想要填写的字段被称为"Nachnamevalue",就像我今天早上在互联网上看到的那样.
我的网页的html代码(只有有趣的部分)看起来像这样:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
'{here there are info on the style, which i'm gonna ignore}
</style>
</head>
<body bgcolor="#ffffcc"><table width="1000"><tbody><tr><td>
<form name="Suchform" action="index.cfm" method="get" target="bottom_window">
Nachname:
<select name="Nachnamepulldown" class="font09px" onchange="wait_and_search()">
<option value="BEGINS_WITH">beginnt mit
<option value="EQUAL">ist
<option value="CONTAINS">enthält
</option></select>
<input name="Nachnamevalue" onkeyup="wait_and_search()" type="text" size="8">
Abteilung:
<select name="Abteilungpulldown" class="font09px" onchange="wait_and_search()">
<option value="BEGINS_WITH">beginnt mit
<option value="EQUAL">ist
<option value="CONTAINS">enthält
</option></select>
<input name="Abteilungvalue" onkeyup="wait_and_search()" type="text" size="3">
<input name="fuseaction" type="hidden" value="StdSearchResult">
<input type="submit" value="suchen">
<script language="JavaScript" type="text/JavaScript">
document.Suchform.Nachnamevalue.focus();
</script>
</form>
</td></tr></tbody></table></body>
</html>
Run Code Online (Sandbox Code Playgroud)
还有(我不知道它是否可以帮助)一个"嵌入式"javascript,每次在"Nachnamevalue"输入框中写入至少2个字符时,它会带来搜索结果.
我究竟做错了什么?
编辑:当我尝试逐步执行Sub时,我得到以下内容:
Set Doc = ie.document
?Doc [object HTMLDocument](在监视列表中它是一个没有任何变量的对象)
GetElementById
通过其id
属性获取元素,但是属性"Nachnamevalue"
的值name
.
要使用名称:
.document.Forms("Suchform").Elements("Nachnamevalue").value = "xxx"
Run Code Online (Sandbox Code Playgroud)