【问题标题】:Using Excel VBA to input a value into Internet Explorer textbox使用 Excel VBA 在 Internet Explorer 文本框中输入值
【发布时间】:2014-08-08 22:53:09
【问题描述】:

VBA/StackOverflow/等的新手。我的代码当前打开 Internet Explorer,导航到 URL,检查它是否已登录,必要时登录,然后导航到新页面。

现在我想在 Internet Explorer 文本框中输入一个字符串值。

以下是相关元素的 HTML 源代码:

<input type="text" class="search_customDate" name="dateFrom" id="dateFrom"
value="mm/dd/yy" size="13" 
onchange="RTSDHTMLUTIL.getRTSDHTML('dateFrom').onChange(event);" 
OnFocus OnBlur />

<input type="text" class="search_customDate" name="dateTo" id="dateTo" 
value="mm/dd/yy" size="13" 
onchange="RTSDHTMLUTIL.getRTSDHTML('dateTo').onChange(event);" 
OnFocus OnBlur />    <INPUT id="dateTo" class="search_customDate" 

<input type="text" class="search_companyLookupField" name="tokens" id="tokens" 
value title OnChange OnMouseOver OnMouseOut OnKeyDown="doLookup(event);" 
OnKeyUp OnFocus OnBlur OnDisable />

这是我的代码的相关部分:

'Input From and To dates
Dim DateFrom As Object ' MSHTML.HTMLInputElement
Set DateFrom = AppIE.Document.getElementByID("dateFrom")
If Not DateFrom Is Nothing Then
    DateFrom(0).Value = "05/05/05"
End If

Dim DateTo As Object ' MSHTML.HTMLInputElement
Set DateTo = AppIE.Document.getElementByID("dateTo")
If Not DateTo Is Nothing Then
    DateTo(0).Value = "06/06/06"
End If

Dim Ticker As Object ' MSHTML.HTMLInputElement
Set Ticker = AppIE.Document.getElementByID("tokens")
If Not Ticker Is Nothing Then
   Ticker(0).Value = "XYZ"
End If

到目前为止,文本框中没有任何内容,我似乎无法弄清楚原因。希望得到任何人的意见/建议。

谢谢

【问题讨论】:

    标签: vba internet-explorer excel


    【解决方案1】:

    这就是我要开始的地方:

    • 删除 HTML 元素变量名称后的“(0)” - getElementByID 方法返回唯一元素,而不是集合
    • 确保您尝试检索的 HTML 输入元素实际上没有返回任何内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-03
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多