vba - 打开多个网站

时间:2014-11-17 00:00:33

标签: excel vba internet-explorer excel-vba

请协助解决以下问题。

背景

我在B栏输入25个股票代码。 我想自动在Internet Explorer中打开它们。

问题:

运行以下代码后,它只打开1个Internet Explorer窗口。网址是" http://finance.yahoo.com/q?s="

如何打开多个Internet Explorer窗口/标签并导航到我想要的股票代码。而不只是一个Internet Explorer窗口弹出?

我的电脑信息:

1.window 8.1

2.excel 2013

3.ie 11

我的Excel参考:

Microsoft Object Library:是

Microsoft Internet Controls:是

Microsoft Form 2.0对象库:是

Microsoft Script Control 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

干杯!

2 个答案:

答案 0 :(得分:1)

navigate命令之后,您需要允许ie对象时间来获取网页。

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

答案 1 :(得分:0)

您是否尝试过创建多个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