2016-04-23 57 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