【问题标题】:Open links from excel one by one to Internet Explorer从excel一一打开到Internet Explorer的链接
【发布时间】:2017-04-03 07:20:06
【问题描述】:

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

我想:

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

2.等待页面完全加载。

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

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

【问题讨论】:

  • 似曾相识?我确定我在上周左右看到了同样的问题。
  • 我编辑了代码。有点相同的问题。

标签: excel internet-explorer vba


【解决方案1】:

此代码循环遍历 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

【讨论】:

  • 肺。这里有一个错误:IE.Navigate Trim(rng.Value)
猜你喜欢
  • 1970-01-01
  • 2016-04-23
  • 2017-04-08
  • 1970-01-01
  • 1970-01-01
  • 2016-03-13
  • 1970-01-01
  • 1970-01-01
  • 2014-01-01
相关资源
最近更新 更多