循环IE找到网址

时间:2016-11-18 18:49:10

标签: vba

我试图编写一个vba脚本来循环运行IE并检测网址'Itinerary'中的文本字符串

然后输入2个字段: 码 姓

然后点击“确定”

加载完成后可见

谢谢 杰

1 个答案:

答案 0 :(得分:0)

这将遍历IE中所有打开的选项卡,并将URL返回到A列 然后,您可以搜索字符串并返回找到的单元格的地址。之后,您可以将CodeSurname(无论是什么?)添加到该单元格。 使用此http://vba-corner.livejournal.com/4623.html来确定如何在IE中打开新编辑的URL。

Option Explicit

Sub GetURLofOpenIETabs()
    Dim mainWorkBook As Workbook
    Dim i As Integer
    Dim objShell As Object, objAllWindows As Object
    Dim ow
    Dim rngSearch As Range

    i = 2

    Set objShell = CreateObject("Shell.Application")
    Set objAllWindows = objShell.Windows
    Set mainWorkBook = ActiveWorkbook

    For Each ow In objAllWindows
        If (InStr(1, ow, "Internet Explorer", vbTextCompare)) Then
            mainWorkBook.Sheets("Sheet1").Range("A" & i) = ow.locationURL
            i = i + 1
        End If
    Next

    Set rngSearch = Sheet1.Cells.Find("text to find")

    If rngSearch Is Nothing Then
    ' do nothing
    Else
        MsgBox rngSearch.Address
    End If
End Sub