Macos Mac OSX Excel 2011 VBA上的WinHttpRequest
Mac版Excel 2011的“参考”中没有WinHttopRequest。我在其他帖子中看到过以下方法:Macos Mac OSX Excel 2011 VBA上的WinHttpRequest,macos,excel,vba,Macos,Excel,Vba,Mac版Excel 2011的“参考”中没有WinHttopRequest。我在其他帖子中看到过以下方法: Set HTTP = CreateObject("MSXML2.ServerXMLHTTP") 这给了我一个“429”运行时错误:ActiveX控制器无法创建对象 有没有办法在Mac Excel上使用WinHttpRequest或类似的东西?我在查询表方面也不走运,希望避免这种解决方案。 我认为应该有一个简单的http GET解决方案来解决这个问题。只是在Mac Excel中找不到它 我
Set HTTP = CreateObject("MSXML2.ServerXMLHTTP")
这给了我一个“429”运行时错误:ActiveX控制器无法创建对象
有没有办法在Mac Excel上使用WinHttpRequest或类似的东西?我在查询表方面也不走运,希望避免这种解决方案。
我认为应该有一个简单的http GET解决方案来解决这个问题。只是在Mac Excel中找不到它
我正在尝试从Yahoo Finance api url获取数据:
Dim URL As String: URL = "http://finance.yahoo.com/d/quotes.csv?s=" & Symbols & "&f=snl1hg"
Dim HTTP As New WinHttpRequest
HTTP.Open "GET", URL, False
HTTP.Send
我知道这在windows上有效,但我使用的是Mac电脑。请告知。谢谢 我不相信Mac有任何与MSXML.ServerXMLHTTP等价的东西。A是使用查询表。总而言之,该线程建议:
With ActiveSheet.QueryTables.Add(Connection:="URL;http://carbon.brighterplanet.com/flights.txt", Destination:=Range("A2"))
.PostText = "origin_airport=MSN&destination_airport=ORD"
.RefreshStyle = xlOverwriteCells
.SaveData = True
.Refresh
End With
您可以使用QueryTables代替HTTP Get调用(WinHttopRequest),Mac Excel 2011显然不支持该调用。下面的代码对我有用-在列中输入股票代码,从A2开始,在行中输入雅虎财务标签(即a、b、r、n),从B1开始 您可以组合URL以调用csv的YF,然后使用查询表进行调用并将结果粘贴到工作表中 在Mac Excel 2011上工作的代码:
Sub Yahoo_Finance_API_Call_MacExcel2011()
Dim head As Range
Set head = Range("A1")
Dim wb As Workbook 'In the event that you'll use different workbooks
Dim src As Worksheet 'In the event that you'll use different a source worksheet
Dim tgt As Worksheet 'In the event that you'll use different a target worksheet
Set wb = ThisWorkbook
Set src = wb.Sheets("Sheet1")
Set tgt = wb.Sheets("Sheet1")
'Assemble Symbols for API Call
Set rng = Range(head.Offset(1, 0), head.Offset(1, 0).End(xlDown))
For Each cell In rng ' Starting from a cell below the head cell till the last filled cell
Symbols = Symbols & cell.Value & "+"
Next cell
Symbols = Left(Symbols, Len(Symbols) - 1) ' Remove the last '+'
'Assemble Tags or API Call
Set rng = Range(head.Offset(0, 1), head.Offset(0, 1).End(xlToRight))
For Each cell In rng ' Starting from a cell to the right of the head cell till the last filled cell
tags = tags & cell.Value
Next cell
'Build URL
URL = "TEXT;http://finance.yahoo.com/d/quotes.csv?s=" 'Use TEXT to collect API data below
URL = URL & Symbols & "&f=" & tags
'Range("A1").Value = URL 'This will output the assembled URL in a1 for QA if need be
'Call API
With tgt.QueryTables.Add(Connection:= _
URL, _
Destination:=Range(head.Offset(1, 1), head.Offset(1, 1).End(xlDown)))
.RefreshStyle = xlOverwriteCells
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.BackgroundQuery = True
.TextFileCommaDelimiter = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.TextFilePromptOnRefresh = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.SaveData = False
End With
End Sub
我正在寻找一个更直接的http get解决方案。查询表真的是在mac上用excel从yahoo finance获取数据的唯一方法吗?这似乎不太可能。@brno792您能找到一个最佳的方法来做这件事吗?您找到解决方案了吗?面临类似的情况。我还想避免查询表