Visual Basic OpenLinks Excel

问题描述:

使用下面的代码在我的文档的A列中打开一串链接,在打开链接后等待3秒,然后移动到下一个链接,而不是打开一个新窗口或选项卡I希望它只是使用已经打开的窗口。Visual Basic OpenLinks Excel

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 
+0

如果您得到了合适的答案,请记住标记为已解决的问题。看起来你过去可能忽略了这样做。将问题标记为已解决,可以防止其他开发人员在解决问题时处理您的问题。它也有助于其他类似问题的搜索更快地得到答案。谢谢。 – Reafidy 2012-04-19 02:44:39

试试这个:

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 

但是,一如既往,我建议你考虑使用带/尾随着,而不是设置。

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 
+0

谢谢我会试试看,我从其他地方得到了代码,所以我不太确定我将如何使用Withwith Endwith – Tony 2012-04-19 02:43:20

+0

不用担心,请参阅我编辑的关于如何使用的答案。 – Reafidy 2012-04-19 02:47:48

+0

编译错误?无效的外部程序 – Tony 2012-04-19 02:49:21