执行以下vb脚本时接口是未知错误

时间:2017-12-06 05:38:58

标签: vba excel-vba excel

我需要打开IE和网址。之后,我需要点击带标签的链接文字。

Private Sub CommandButton_Click() 

Dim IE As Object
Dim NewURL As String
Dim sURL As String
Dim strCountBody As String
Dim lStartPos As Long
Dim lEndPos As Long
Dim TextIWant As String
Application.ScreenUpdating = False
Set IE = CreateObject("Internetexplorer.Application")

sURL = "My Link" 'hidden for security reasons.
With IE
    .navigate sURL
    ' uncomment the line below if you want to watch the code execute, or for debugging
    .Visible = True
End With
' loop until the page finishes loading
Do While IE.Busy
Loop    

' click a text link on the page after that
Set ElementCol = IE.document.getElementsByTagName("a")
For Each link In ElementCol
    If link.innerHTML = "Link Text" Then
        NewURL = link.GetAttribute("href")
        Exit For
    End If
Next link
With IE
    .navigate NewURL
    ' uncomment the line below if you want to watch the code execute, or for debugging
    .Visible = True
End With
' loop until the page finishes loading
Do While IE.Busy
Loop

End Sub

0 个答案:

没有答案