I try to download a file from a Server in Excel using VBA. This works fine when using HTTP, but doesn't work using HTTPS.
I can reach both adresses (HTTP/HTTPS) in Internet Explorer. If I use URLDownloadToFile
with the HTTP address the file is downloaded.
When using the HTTPSadress
I get return code -2146697211
. Maybe this a certificate Problem?
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Dim Ret As Long
Sub DownloadCode()
Dim strURL As String
Dim strPath As String
strURL = "https:/url.de/module.bas"
strPath = Environ("TEMP") & "\Module.bas"
Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)
If Ret = 0 Then
' MsgBox "File successfully downloaded"
Else
MsgBox "Returncode:" & Ret & " Unable to download Code`enter code here`."
End If
End Sub