使用Excel VBA自动化按键进入IE浏览器按Enter键search“

我正在处理一个网页表单文本字段,当按下“Enter”键时,将启动对其内容的search。 我知道如何启动所有其他事件侦听器,但我无法得到按下“Enter”事件触发。 它没有列出与其他常见的。 即onchange,onclick,onblur

目前,我正在使用CreateObject(“Shell.Application”)作为Excel VBA中的父对象来控制现有的IE浏览器。

我也尝试过sendkeys,但在VBA注意力方面遇到麻烦。 它在我的IDE或电子表格本身中键入。

这不是一个公共的网站。 它是事件(模糊,更改,焦点,keydown,mousedown,mousemove)的input标记。

With Tex_Box .focus .keydown .innertext = Field_Text .change .focus .blur End With 

任何帮助将是伟大的! 提前致谢。

所以stackoverflow.com/questions/11655591/…不会重复如何使用Sendkeys之前的Internet Explorer焦点。 但是,这只是谜题的一部分,我仍然要求它把重点放在文本字段上,然后按Enter键。 由于不知道需要多less个标签才能find正确的字段,我只是简单地创build了一个循环,直到部分string“focus”在文本字段的类名中。 一旦发生这种情况,我把它发送到“〜”。

 Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long Dim HWNDSrc As Long text_again: With DOCK_Tex_Box .focus .keydown .innertext = Field_Text .change Sleep (500) .focus .blur HWNDSrc = IE.HWND For i = 1 To 100 DoEvents SetForegroundWindow HWNDSrc DoEvents Application.SendKeys ("{TAB}"), True DoEvents Sleep 1000 If InStr(.classname, "prompt") > 0 Then 'If the for loop goes to quickly the field loses focus and then the text clears out. DoEvents Sleep 500 GoTo text_again: End If If InStr(.classname, "focus") > 0 Then 'Text field has focus Sleep 1000 Exit For End If Next End With Application.SendKeys ("~"), True DoEvents Sleep 500