Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 用于从框架访问网页的vba脚本_Excel_Vba - Fatal编程技术网

Excel 用于从框架访问网页的vba脚本

Excel 用于从框架访问网页的vba脚本,excel,vba,Excel,Vba,我试图使用VBA脚本excel宏从网站下载数据,但我感兴趣的数据驻留在网页框架内,主页和框架的url没有得到更改 以下是宏,这是工作良好的主页,请帮助我从一个网页框架下载相同的 'Microsoft HTML Office Library Sub webtable_NSE() Dim HTMLDoc As New HTMLDocument Dim objElementsTd As Object Dim objTd As Object Dim lRow As L

我试图使用VBA脚本excel宏从网站下载数据,但我感兴趣的数据驻留在网页框架内,主页和框架的url没有得到更改

以下是宏,这是工作良好的主页,请帮助我从一个网页框架下载相同的

 'Microsoft HTML Office Library
Sub webtable_NSE()
    Dim HTMLDoc As New HTMLDocument
    Dim objElementsTd As Object
    Dim objTd As Object
    Dim lRow As Long
    Dim myarray()
    Dim oIE As InternetExplorer
    Set oIE = New InternetExplorer
    oIE.navigate "https://www.nseindia.com/products/content/equities/ipos/ipo_current_quess.htm"

    'javascript:loadIpoBidDetails('/products/content/equities/ipos/Quess_curr_ipo_bid_details.htm')
    'oIE.Navigate "https://www.nseindia.com/products/content/equities/ipos/Quess_curr_ipo_bid_details.htm"

    Do Until (oIE.readyState = 4 And Not oIE.Busy)
        DoEvents
    Loop

    Application.Wait (Now + TimeValue("0:00:03"))
    HTMLDoc.body.innerHTML = oIE.Document.body.innerHTML
    With HTMLDoc.body
        Set elemcollection = .getElementsByTagName("Table")
        For t = 0 To elemcollection.Length - 1
            For r = 0 To elemcollection(t).Rows.Length - 1
                For c = 0 To elemcollection(t).Rows(r).Cells.Length - 1
                    ThisWorkbook.Sheets("NSE").Cells(ActRw + r + 1, c + 1) = elemcollection(t).Rows(r).Cells(c).innerText
                Next c
            Next r
            ActRw = ActRw + elemcollection(t).Rows.Length + 1
        Next t
    End With
    oIE.Quit
End Sub

没有VBA,您可能可以做您想做的事情


在“数据”选项卡中,您可以单击“来自Web”,地址:并单击“导入”。之后,您可以将连接属性更改为“打开文件时刷新数据”,或控制何时使用VBA刷新数据。如果不使用VBA,您可能可以随心所欲


在“数据”选项卡中,您可以单击“来自Web”,地址:并单击“导入”。在此之后,您可以将连接属性更改为“打开文件时刷新数据”,或控制何时使用VBA刷新数据。如果您知道包含所需表数据的URL,则无需尝试并自动执行IE“到达”,您只需针对该特定URL发送HTTP请求即可。您正在查找的库是MSXML2 XMLHTTP-以下是返回数据的代码示例:

Option Explicit

Sub GetTableData()

    Dim objRequest As Object
    Dim strUrl As String
    Dim strHtml As String
    Dim blnAsync As Boolean

    Set objRequest = CreateObject("MSXML2.XMLHTTP")
    strUrl = "https://www.nseindia.com/products/content/equities/ipos/QUESS_curr_ipo_bid_details.htm"
    blnAsync = True

    With objRequest
        .Open "GET", strUrl, blnAsync
        .Send
        While .readyState <> 4
            DoEvents
        Wend
        strHtml = .responseText
    End With

    Debug.Print strHtml

End Sub
选项显式
子GetTableData()
Dim objRequest作为对象
暗弦
作为字符串的Dim strHtml
Dim blnAsync作为布尔值
Set objRequest=CreateObject(“MSXML2.XMLHTTP”)
strUrl=”https://www.nseindia.com/products/content/equities/ipos/QUESS_curr_ipo_bid_details.htm"
blnAsync=True
带objRequest
.打开“获取”,strUrl,blnAsync
.发送
While.readyState 4
多芬特
温德
strHtml=.responseText
以
Debug.Print strHtml
端接头

如果您知道包含所需表格数据的URL,则不必尝试并自动执行IE“到达目的地”——您只需针对该特定URL发送HTTP请求即可。您正在查找的库是MSXML2 XMLHTTP-以下是返回数据的代码示例:

Option Explicit

Sub GetTableData()

    Dim objRequest As Object
    Dim strUrl As String
    Dim strHtml As String
    Dim blnAsync As Boolean

    Set objRequest = CreateObject("MSXML2.XMLHTTP")
    strUrl = "https://www.nseindia.com/products/content/equities/ipos/QUESS_curr_ipo_bid_details.htm"
    blnAsync = True

    With objRequest
        .Open "GET", strUrl, blnAsync
        .Send
        While .readyState <> 4
            DoEvents
        Wend
        strHtml = .responseText
    End With

    Debug.Print strHtml

End Sub
选项显式
子GetTableData()
Dim objRequest作为对象
暗弦
作为字符串的Dim strHtml
Dim blnAsync作为布尔值
Set objRequest=CreateObject(“MSXML2.XMLHTTP”)
strUrl=”https://www.nseindia.com/products/content/equities/ipos/QUESS_curr_ipo_bid_details.htm"
blnAsync=True
带objRequest
.打开“获取”,strUrl,blnAsync
.发送
While.readyState 4
多芬特
温德
strHtml=.responseText
以
Debug.Print strHtml
端接头