Issue
How to download a file from URL to a string variable without saving it to local drive? Similarly to this method in C# I would like it in VBA: href="https://stackoverflow.com/q/3231969/1903793">Download file from URL to a string
Here is something with download file to disc space: How do i download a file using VBA (Without internet explorer) While it can be some hint, I would like to avoid this intermediate step of getting the file to string.
Solution
With WinHttpRequest
class you can achieve the file, the .Open method need 2 args: the request method "GET"/"POST", the URL string.
The third arg is optional, boolean, default is True for asynchronous mode:
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.Send
httpRequest.WaitForResponse
Debug.Print httpRequest.Status
Debug.Print httpRequest.ResponseText
mystring = httpRequest.ResponseText
Then you get the file in the var name mystring
Answered By - Trimax Answer Checked By - David Marino (WPSolving Volunteer)