【问题标题】:Import data from URL into excel将数据从 URL 导入 excel
【发布时间】:2018-06-16 14:04:18
【问题描述】:

我是 excel vba 的新手。我在网站 URL 中有数据。我需要导入工作簿表。我可以创建工作表并导入,而我想导入特定的工作表。

这个作品

Sub Test()
    Application.DisplayAlerts = False
    strURL = "https://www.nseindia.com/products/dynaContent/equities/equities/histscrip.jsp?symbolCode=1693&symbol=AXISBANK&symbol=axisbank&segmentLink=17&symbolCount=1&series=ALL&dateRange=1month&fromDate=&toDate=&dataType=PRICEVOLUMEDELIVERABLE"
    Application.Workbooks.Open (strURL)
    Application.DisplayAlerts = True
End Sub

但以下修改代码不起作用。任何帮助将不胜感激。

Sub OpenCSV()
Application.DisplayAlerts = False
strURL = "https://www.nseindia.com/products/dynaContent/equities/equities/histscrip.jsp?symbolCode=1693&symbol=AXISBANK&symbol=axisbank&segmentLink=17&symbolCount=1&series=ALL&dateRange=1month&fromDate=&toDate=&dataType=PRICEVOLUMEDELIVERABLE"
Worksheets("dump").Range("A1").Select
With Selection
    .Open (strURL)
End With
Application.DisplayAlerts = True

End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    使用查询表并指定目标工作表和范围。

    Option Explicit
    Public Sub testing()
        Dim qt As QueryTable
        Dim ws As Worksheet
    
        Set ws = ThisWorkbook.Worksheets("Sheet1")
    
        Const URL As String = "https://www.nseindia.com/products/dynaContent/equities/equities/histscrip.jsp?symbolCode=1693&symbol=AXISBANK&symbol=axisbank&segmentLink=17&symbolCount=1&series=ALL&dateRange=1month&fromDate=&toDate=&dataType=PRICEVOLUMEDELIVERABLE"
        Set qt = ws.QueryTables.Add(Connection:="URL;" & URL, Destination:=ws.Range("A1"))
    
        With qt
            .RefreshOnFileOpen = True
            .FieldNames = True
            .WebSelectionType = xlSpecifiedTables
            .WebTables = 1
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-02
      相关资源
      最近更新 更多