I use Microsoft.XMLHTTP via VBA to pull out the body of a webpage. However, characters such as é are replaced with the character “?” or something equally not useful.
Here is the basic code:
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", ThisWebPage, False
objHTTP.setRequestHeader "Content-Type", _
"application/x-www-form-urlencoded; charset=UTF-8"
objHTTP.Send ("")
strResponse = objHTTP.responseText
Is there a way to restore a page with intact characters?
Note: I also tried using this request header without success:
objHTTP.setRequestHeader "Content-Type", "content=text/html; charset=iso-8859-1"
Thanks in advance.
Solution
Thanks to Ben.Vineyard (and some quick Googling), I can pull out accented characters with the following code:
' Create the XMLHTTP object
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
' Send the request
objHTTP.Open "GET", WhatWebPage, False
objHTTP.Send ("")
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
With BinaryStream
.Type = adTypeBinary
.Open
.Write objHTTP.ResponseBody
'Change stream type To binary
.Position = 0
.Type = adTypeText
'Specify charset For the source text (unicode) data.
.Charset = "iso-8859-1"
'Open the stream And get binary data from the object
strResponse = .ReadText
End With
source
share