vba – 打开多个网站

请协助解决以下问题。

背景:

我在列B中input25个股票代码。我想自动在Internet Explorer中打开它们。

问题:

运行下面的代码后,它只打开1个Internet Explorer窗口。 而url是“ http://finance.yahoo.com/q?s= ”

我如何能够打开多个Internet Explorer窗口/选项卡,并导航到我想要的股票代码。 而不是只popup一个Internet Explorer窗口?

我的电脑信息:

1.窗口8.1

2.excel 2013

3.ie 11

我的excel参考:

微软对象库:是的

微软互联网控制:是的

Microsoft Form 2.0对象库:是的

微软脚本控制1.0:是的

url:

http://finance.yahoo.com/q?s=ibm

以下是我的VBA代码:

Private Sub CommandButton1_Click() Dim ie As Object Set ie = CreateObject("InternetExplorer.Application") For r = 2 To 50 With ie .Visible = 1 .navigate "http://finance.yahoo.com/q?s=" & Cells(r, "B").Value End With Next r End Sub 

干杯!

navigate命令后,你需要让对象的时间来获得网页。

 Dim ie As Object Set ie = CreateObject("InternetExplorer.Application") For r = 2 To 50 With ie .Visible = 1 .navigate "http://finance.yahoo.com/q?s=" & Cells(r, "B").Value Do While (.Busy Or .ReadyState <> 4): DoEvents: Loop 'READYSTATE_COMPLETE = 4 ' do something with the page here End With Next r ie.quit: set ie = nothing 

你有没有尝试过创build多个IE对象?

 Private Sub CommandButton1_Click() Dim ie As Object For r = 2 To 50 Set ie = CreateObject("InternetExplorer.Application") With ie .Visible = 1 .navigate "http://finance.yahoo.com/q?s=" & Cells(r, "B").Value End With Next r End Sub