2016-04-23 78 views
0

我是Excel VBA的新手。我目前正在做IE浏览器自动化的Excel,我想点击网页上的标签。VBA Excel单击标签

的HTML源代码是:

<td class = t19TabItem><a href="javascript:apex.submit('D_Price');">Compliance</a></td> 

任何帮助,点击标签符合性。

我使用了下面的代码,通过使用inner html发现了标签合规性,但它没有点击compliance标签。它会抛出错误,因为对象不包含此属性。

set link=IE.document.getElementsByTagName("a") 
if link.InnerHTML="compliance" and link.href="javascript:apex.submit('D_Price')" then 
    click link 
end if 

如何点击合规性标签?

+0

HTML源代码上面的代码有问题 Compliance Shekar

回答

0

尝试引用下面

Microsoft HTML对象库

Microsoft Internet控制**

Sub test() 
Dim oHTML_Element As IHTMLElement 
Dim oBrowser As InternetExplorer 
Dim ie As Variant 
Set ie = CreateObject("InternetExplorer.Application") 
ie.Visible = True 
ie.navigate "your web link" 'Your weblink goes here 
While ie.readyState <> READYSTATE_COMPLETE And ie.readyState <> READYSTATE_LOADED 
    DoEvents 
Wend 
Application.Wait (Now() + TimeValue("00:00:03")) 
For Each oHTML_Element In ie.document.getElementsByTagName("a") 
    If oHTML_Element.innerHTML = "compliance" Then 
     oHTML_Element.Click 
    End If 
Next 
End Sub 
+0

非常感谢karthick fo你的快速帮助:-)。它正在工作。 – Shekar

+0

然后请将其标记为解决方案(通过勾选勾号)。所以对于其他开发人员来说,找到解决方案代码也很有用。 –

+0

你可以请给我一些参考,如何选择类型在excel vba中声明变量/元素/对象,因为我遇到频繁的错误“对象不支持此属性或方法”。 例如,您在答案中提到的 Dim oHTML_Element作为IHTMLElement。 – Shekar