Excel vba通过web查询提取损益表/资产负债表/现金流量表



我能够使用链接"http://www.advfn.com/stock-market/NASDAQ/NVDA/financials?btn=annual_reports&mode=company_data"上的web查询将财务报表导入excel。我将导入过程记录到一个宏中,并对vba代码进行了一些修补以使其运行。现在,我想根据单元格A1中的股票报价机刷新导入的财务报表。然而,我得到一个下标是超出范围的错误,我似乎无法弄清楚为什么。请查看下面的代码,并提供您的见解,如果可能的话。

Sub finstate()
'
' finstate Macro
'
'
  With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://www.advfn.com/stock-market/NASDAQ/" & Worksheets("Input").Range("A1").Value & "/financials?btn=annual_reports&mode=company_data" _
    , Destination:=Range("B2"))
    .Name = "financials?btn=annual_reports&mode=company_data"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = False
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingAll
    .WebTables = "6"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
End With
End Sub

非常感谢!

我认为这可能是您的参考资料,看起来您正在从输入表中读取报价器值,但试图写入活动表。因为除了这种可能性之外,它似乎对我很有效。

我为当前工作表添加了一个变量和测试。字体的第一行也有一点变化。

  sTicker = Range("A1").Value
  If sTicker = "" Then
    MsgBox "No value to look up"
    Exit Sub
  End If
  With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://www.advfn.com/stock-market/NASDAQ/" & sTicker & "/financials?btn=annual_reports&mode=company_data" _
    , Destination:=Range("B2"))

最新更新