下面的宏在Excel 2010中運行,但在Excel for Mac 2011中,我在.Web命令上收到錯誤。是否有Windows版本和Mac版本的命令列表?將Excel 2010中創建的宏轉換爲Excel Mac 2011
宏從股票中下載財務數據,其符號列在列H中。感興趣的數據僅在某些表中,而不是全部,所以命令「.webtables」。這些數據被複制到電子表格的另一部分,數據被清除並繼續,直到符號列表被用盡。
遇到錯誤:
在下面一行,則宏停止和Excel關閉工作:
.Name = "Yahoo analyst estimates"
上面的行更改爲:
.Name = False
允許宏繼續,但沒有任何「.web」命令被解釋。
所以我的關鍵問題是要找到「名.web」像Excel的命令列表中的Mac 2011
' 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
據我所知,目前還無處列出Mac和Windows之間的VBA Excel的所有許多差異,特別是因爲它的版本也各不相同。 – Rory