Dateidownload per vba unter O2016
21.02.2018 18:47:46
Harry
vorab es geht um Office 365/2016 und nicht um 2013. Seit ca. 10 Jahren nutze ich die auch hier im Forum häufiger erwähnte Form mittels wininet.dll, um in vba eine Datei aus den Internet zu laden. Funktioniert hat diese unter 2007/2010/2013. Heute bei einer Testinstallation von 2016 funktioniert diese nicht mehr (sowohl in Excel als auch in Access in Benutzung)
Wurde hier etwas geändert? Oder gibt es mittlerweile bessere Wege? Bin da nicht auf dem laufenden weil einem funktionierendem Gaul schaut man nicht ins Maul oder so..
Private Declare Function InternetOpen Lib "wininet.dll" Alias _
"InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long, _
ByVal lpszProxyName As String, _
ByVal lpszProxyBypass As String, _
ByVal dwFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias _
"InternetOpenUrlA" (ByVal hInternetSession As Long, _
ByVal lpszUrl As String, _
ByVal lpszHeaders As String, _
ByVal dwHeadersLength As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal lpBuffer As String, _
ByVal dwNumberOfBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer
Sub CopyURLToFile(ByVal url As String, ByVal Filename As String)
Dim hInternetSession As Long
Dim hUrl As Long
Dim DatNum As Integer
Dim ByteAnz As Long
Dim Buffer As String * 4096
Dim DatInhalt As String
On Error GoTo Err_Sub
If Len(url) = 0 Or Len(Filename) = 0 Then
MsgBox "Fehlende URL"
Exit Sub
End If
' open an Internet session, and retrieve its handle
hInternetSession = InternetOpen("dummy", INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0)
If hInternetSession = 0 Then
MsgBox "Fehler bei InternetOpen"
Exit Sub
End If
' open the file and retrieve its handle
hUrl = InternetOpenUrl(hInternetSession, url, vbNullString, 0, _
INTERNET_FLAG_EXISTING_CONNECT, 0)
If hUrl = 0 Then
If hInternetSession Then InternetCloseHandle hInternetSession
MsgBox "Fehler bei InternetOpenUrl"
Exit Sub
End If
...
hUrl hat bei mir immer 0 (zeitgleich unter älterem Office klappen die Tests aber). Und falls relevant - Url ist https mit user:passwort
Besten Dank vorab für Antwort
Harry