I am using Windows 10
This question is identical to VBA: An error occurred in the secure channel support but with TLS1.3 and not TLS1.2, and also @KarlH7's solution did not work for me.
Function ReadURLIntoString(url)
Dim url As String
Dim xmlhttp As Object
Dim responseText As String
' Create a new instance of MSXML2.ServerXMLHTTP
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
' Open a GET request to the URL
xmlhttp.Open "GET", url, False
' Send the request
xmlhttp.send
' Check if the request was successful (status code 200)
If xmlhttp.Status = 200 Then
' Get the response text
responseText = xmlhttp.responseText
' Now, responseText contains the contents of the URL
'remove line breaks
ReadURLIntoString = Trim(Replace(Replace(responseText, Chr(10), ""), Chr(13), ""))
Else
' If the request was not successful, handle the error
MsgBox "Error: " & xmlhttp.Status & " - " & xmlhttp.StatusText
End If
End Function
The VBA reads a code from a website.
After I moved the website to TLS 1.3 (using CloudFlare) then this VBA fails at .send
with the error Run-time error '-2147012739 (80072f7d)': An error occurred in the secure channel support
I tried the following with no success
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
and experimenting with xmlhttp.setOption(2)=...
Internet Properties/Security/Use TLS 1.3 (Experimental)
and rebooting.Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client\Enabled
=1 as per here and here and rebooting.Any ideas?
The only way I managed to solve this is by calling cURL from VBA.
Here is simple code to do this. Obviously curl.exe has to be in the C:\temp directory for this to work.
command = "C:\temp\curl -s -o C:\temp\temp.txt """ & url & """"
Call Shell(command)
and then reading the contents of C:\temp\temp.txt
Note that the Shell runs asynchronously, so one needs to wait until it has finished. One can do this using omegastripe's suggestion in Excel VBA Wait For Shell to Finish before continuing with script
Public Sub RunCMD(ByVal strCMD As String)
'Runs the provided command
Dim wsh As Object
Set wsh = CreateObject("WScript.Shell")
Call wsh.Run(strCMD, 2, True)
End Sub
RunCmd(command)
instead of
Shell (command)