Excel for Mac(VBA)版本15.29.1中的Curl POST
我需要从运行在Mac(版本15.29.1)上的Excel进行一系列调用 我发现了一些,如下所示,但我不断得到: 运行时错误5(过程调用无效) 这里有人能帮忙解决吗 提前谢谢Excel for Mac(VBA)版本15.29.1中的Curl POST,curl,vba,excel,Curl,Vba,Excel,我需要从运行在Mac(版本15.29.1)上的Excel进行一系列调用 我发现了一些,如下所示,但我不断得到: 运行时错误5(过程调用无效) 这里有人能帮忙解决吗 提前谢谢 Option Explicit ' execShell() function courtesy of Robert Knight via StackOverflow ' https://stackoverflow.com/questions/6136798/vba-shell-function-in-office-2011
Option Explicit
' execShell() function courtesy of Robert Knight via StackOverflow
' https://stackoverflow.com/questions/6136798/vba-shell-function-in-office-2011-for-mac
Private Declare PtrSafe Function popen Lib "libc.dylib" (ByVal command As String, ByVal mode As String) As LongPtr
Private Declare PtrSafe Function pclose Lib "libc.dylib" (ByVal file As LongPtr) As Long
Private Declare PtrSafe Function fread Lib "libc.dylib" (ByVal outStr As String, ByVal size As LongPtr, ByVal items As LongPtr, ByVal stream As LongPtr) As Long
Private Declare PtrSafe Function feof Lib "libc.dylib" (ByVal file As LongPtr) As LongPtr
Function execShell(command As String, Optional ByRef exitCode As Long) As String
Dim file As LongPtr
file = popen(command, "r")
If file = 0 Then
Exit Function
End If
While feof(file) = 0
Dim chunk As String
Dim read As Long
chunk = Space(50)
read = fread(chunk, 1, Len(chunk) - 1, file)
If read > 0 Then
chunk = Left$(chunk, read)
execShell = execShell & chunk
End If
Wend
exitCode = pclose(file)
End Function
Function HTTPGet(sUrl As String, sQuery As String) As String
Dim sCmd As String
Dim sResult As String
Dim lExitCode As Long
sCmd = "curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d """ & sQuery & """" & " " & sUrl
MsgBox (sCmd)
sResult = execShell(sCmd, lExitCode)
' ToDo check lExitCode
HTTPGet = sResult
End Function
错误发生在哪一行?