从excel逐个打开到Internet Explorer的链接

时间:2017-04-03 07:20:07

标签: excel excel-vba internet-explorer vba

我在Excel中有超过100个链接,我想逐个在Internet Explorer中打开它们。分配给我的计算机有点慢,这就是需要在Internet Explorer的一个选项卡中打开链接的原因。

我想:

1.从A1复制链接,将其粘贴到Internet Explorer。

2.等待页面完全加载。

3.从A2复制链接,将其粘贴到Internet Explorer(相同的选项卡,不打开a     新标签)。

4.等待页面完全加载。

5.重复步骤,直到带有链接的“A”的最后一个单元格。

在下面的代码中,我可以从A1导航链接。如何循环它将从单元格1导航到单元格X。

Sub OpenInAnotherBrowser()
Dim iePath As String
Dim browser As String
Dim URL As String

iePath = "C:\Program Files\Internet Explorer\iexplore.exe"

If Dir(iePath) = "" Then pathie = "C:\Program Files\Internet Explorer\iexplore.exe"

URL = ActiveSheet.Range("A1").Value

If Dir(iePath) = "" Then
    If MsgBox("IE Not Found, Open with default browser?", vbQuestion + vbYesNo) = vbYes Then
        Application.FollowHyperlink URL
        Exit Sub
    End If
End If

Shell """" & iePath & """" & URL, vbHide

End Sub

1 个答案:

答案 0 :(得分:0)

此代码循环遍历sheet1中A列中的链接。请留意断开的链接以及类似的内容,因为此代码中没有检查这些内容。

Sub Main()

Dim IE As Object
Dim rngURL As Range
Dim rng As Range

' not perfect, but it is a quick way to keep VBA from looping through 1000000+ rows without using a bunch of ifs....
Set rngURL = Intersect(Sheet1.UsedRange, Sheet1.Columns("A"))

Set IE = CreateObject("internetexplorer.application")

IE.Visible = True

For Each rng In rngURL

    rng.Select

    If Trim(rng.Value) <> "" Then

        IE.Navigate Trim(rng.Value)

        Do While IE.ReadyState <> READYSTATE_COMPLETE
        Loop

        MsgBox IE.LocationURL ' This is just to slow things down a little bit

    End If

Next rng

IE.Quit

End Sub