Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String VBA将文件下载到字符串变量_String_Vba_Excel_Curl - Fatal编程技术网

String VBA将文件下载到字符串变量

String VBA将文件下载到字符串变量,string,vba,excel,curl,String,Vba,Excel,Curl,如何将文件从URL下载到字符串变量,而不将其保存到本地驱动器?与C#中的此方法类似,我希望在VBA中使用此方法: 这里是下载文件到光盘空间的一些东西:虽然这可能是一些提示,但我希望避免将文件设置为字符串的中间步骤 使用WinHttpRequest类可以实现文件,.Open方法需要两个参数:请求方法“GET”/“POST”,URL字符串。 第三个参数是可选的布尔值,对于异步模式,默认值为True: Set httpRequest = CreateObject("WinHttp.WinHttpReq

如何将文件从URL下载到字符串变量,而不将其保存到本地驱动器?与C#中的此方法类似,我希望在VBA中使用此方法:


这里是下载文件到光盘空间的一些东西:虽然这可能是一些提示,但我希望避免将文件设置为字符串的中间步骤

使用
WinHttpRequest
类可以实现文件,.Open方法需要两个参数:请求方法“GET”/“POST”,URL字符串。
第三个参数是可选的布尔值,对于异步模式,默认值为True:

Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://urlo_of_the_file_you_want"
httpRequest.Open "GET", URL, False
httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
httpRequest.WaitForResponse
Debug.Print httpRequest.Status
Debug.Print httpRequest.ResponseText
mystring = httpRequest.ResponseText
然后在var name
mystring