以下宏在Excel 2010中运行,但在Excel for Mac 2011中,我在.Web命令上收到错误。是否有Windows版本和Mac版本的命令列表?
宏从股票下载财务数据,列H中列出的符号。感兴趣的数据仅在某些表中,而不是全部,所以命令“.webtables”。此数据将复制到电子表格的另一部分,数据将被清除并继续,直到符号列表用完为止。
遇到错误:
在以下行中,宏停止,Excel将关闭工作簿:
.Name = "Yahoo analyst estimates"
将以上行更改为:
.Name = False
允许宏继续,但不解释“.web”命令。
所以我的关键问题是找到Excel for Mac 2011的“.web”列表。
' Download_Yahoo_Metrics Macro
' Downloads Tables for Analyst Estimates, Analyst Opinion and Key Statistics
'
Dim ScrURL As String
lr = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row 'delimits the last row
fr = ActiveSheet.Cells(1, "C") 'delimits the first row
For r = fr To lr
Range("B5:F53").ClearContents 'clear previous
ScrURL = "URL;http://finance.yahoo.com/q/ae?s=" & ActiveSheet.Cells(r, "H")
'
With ActiveSheet.QueryTables.Add(Connection:=ScrURL, Destination:=Range("B5"))
.Name = "Yahoo analyst estimates"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "8,11,14,17,20,23"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = True
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
With ActiveSheet
.Cells(r, "i") = .Range("C47")
.Cells(r, "j") = .Range("D47")
.Cells(r, "k") = .Range("F47")
.Cells(r, "l") = .Range("C48")
.Cells(r, "m") = .Range("C49")
.Cells(r, "n") = .Range("D49")
.Cells(r, "o") = .Range("F49")
End With
Next
Range("A1").Select
End Sub
答案 0 :(得分:0)
问题必须是连接,而不是QueryTable的名称。 尝试删除连接,然后才创建表。 在这里,您有一个可以帮助您的链接: http://www.dummies.com/how-to/content/using-a-web-query-to-load-tables-in-excel-2011-for.html