VBA无法使用getelementsby方法从输入或表单类型中提取值

时间:2014-11-11 12:04:15

标签: excel vba getelementsbytagname

我有一些问题需要从表单或输入类型中检索值。我希望你能帮助我或给我一些建议。

我的电脑信息:

1.window 8.1

2.excel 2013

3.ie 11

我的Excel参考:

Microsoft Object Library:是

Microsoft Internet Controls:是

Microsoft Form 2.0对象库:是

Microsoft Script Control 1.0:是的

预期结果:

检索值“AQFFmT0qn1TW”并自动将其复制到Cell(“c2”)。

实际结果:

没有返回Cell(“C2”)

URL:

http://coursesweb.net/javascript/getelementsbytagname

以下是HTML元素。

<form rel="async" ajaxify="/plugins/like/connect" method="post" action="/plugins/like/connect" onsubmit="return window.Event &amp;&amp; Event.__inlineSubmit &amp;&amp; Event.__inlineSubmit(this,event)" id="u_0_1">
<input type="hidden" name="fb_dtsg" value="AQFFmT0qn1TW" autocomplete="off">             

以下是我的VBA代码。

Private Sub CommandButton1_Click()
Dim ie As Object
Dim Doc As HTMLDocument
Dim Elements As IHTMLElementCollection
Dim Element As IHTMLElement

Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = 0

ie.navigate "http://coursesweb.net/javascript/getelementsbytagname"
Do
DoEvents
Loop Until ie.readyState = 4

Set Doc = ie.document

Set Elements = Doc.getElementsByTagName("input")

For Each Element In Elements
If Element.name = "fb_dtsg" Then
    Range("c2").Value = Element.innerText
End If
Next Element

Set Elements = Nothing

End Sub    

0 个答案:

没有答案