1

使用以下代码在我的文档的 A 列中打开一堆链接,希望在打开链接后等待 3 秒,然后移至下一个,而不是打开新窗口或选项卡,我希望它只使用该窗口已经打开了。

Sub OpenLinks()

For Each vCell In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
oIE.Navigate (vCell.Value)
Next vCell

End Sub
4

1 回答 1

0

试试这个:

Sub OpenLinks()

Set oIE = CreateObject("InternetExplorer.Application")

For Each vCell In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    oIE.Visible = True
    oIE.Navigate (vCell.Value)
    Application.Wait (Now + TimeValue("0:00:3"))
Next vCell

End Sub

但是,与往常一样,我建议您考虑使用 With/End With 而不是 Set。

Sub OpenLinks()  

With CreateObject("InternetExplorer.Application")

For Each vCell In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
    .Visible = True
    .Navigate (vCell.Value)
    Application.Wait (Now + TimeValue("0:00:3"))
Next vCell

End With

End Sub
于 2012-04-19T02:39:55.640 回答