将Excel 2010中创建的宏转换为Excel Mac 2011



下面的宏在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

问题一定是连接,而不是QueryTable的名称。尝试删除连接,然后创建表。这里有一个可以帮助您的链接:http://www.dummies.com/how-to/content/using-a-web-query-to-load-tables-in-excel-2011-for.html

最新更新