I am using Excel 2007 (12.0.4518.1014)
I have been using the WinHttpRequest Object to perform API GET Requests on a web service that hosts data for me.
Everything else works properly and it grabs the JSON formatted data from the web service and puts it into a string with the .ResponseText
property.
The issue I am having is that inside that string, all of the Unicode characters are turned into gibberish like â??
instead of ✓
(U+2713). Which means that when I do MyRange.Value = .ResponseText
the cell value becomes â??
.
If I set the GET request to ask for Xml format, I get �??
instead of ✓
I have confirmed by repeating the GET request in Chrome, the web service is outputting the correct Unicode symbol, and Chrome was able to show me ✓
. So this is an issue with VBA or WinHttp.
Excel by itself is able to generate Unicode symbols and VBA is able to do it as well ChrW(10003)
.
How can I preserve Unicode symbols during a GET request? Is it possible with WinHttp or do I need to change methods?
Edit:
Here are the headers during a standard response:
{
"access-control-allow-headers": "Content-Type",
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
"access-control-allow-origin": "*",
"cache-control": "private",
"content-encoding": "gzip",
"content-security-policy": "frame-ancestors 'self', default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;",
"content-type": "application/json",
"date": "Wed, 23 Jun 2021 18:08:53 GMT",
"expect-ct": "max-age=0;",
"referrer-policy": "strict-origin-when-cross-origin",
"strict-transport-security": "max-age=31536000; includeSubDomains; preload",
"vary": "Accept-Encoding",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-stackifyid": "V2|80002f92-0000-3100-b63f-84710c7967bb|C61313|CD10436"
}
Update: RESOLVED!
I have solved my problem with advice from @GSerg and wonderful insight from @JoelCoeHoorn. I will write how it was solved here since my question was closed.
WinHTTPRequest was swapped out for an XMLHTTP Object. This Object can be used in VBA with similar commands to WinHTTPRequest, as shown in the link about halfway down the page. But the XMLHTTP object was able to return Unicode characters with no issues.
To use it in VBA, you can create it with the line:
Dim http As Object
Set http = CreateObject("Microsoft.XMLHTTP")
And then you're ready to go with .open
and .setRequestHeader
and .Send
similar to the WinHttpRequest object.