URL Download von generierter Datei
06.06.2017 11:58:57
generierter
meine bisherige Suche im WWW war erfolglos, ich hoffe ihr könnt mir helfen.
Problem:
Für meine Arbeit muss ich regelmäßig auf diese Seite:
https://www.regelleistung.net/ext/data/
Man wählt die gewünschten Parameter aus, setzt ein Häkchen bei "Herunterladen" und klickt auf "anzeigen" um eine CSV-Datei zu erhalten. Diesen Prozess würde ich gerne automatisieren, soll heißen: Eingabefelder in Excel geben die gewünschten Parameter an, dass Makro übernimmt sie und führt die Abfrage automatisch durch.
Ich habe es mit der URLDownloadToFile-Methode probiert, doch leider passiert da nix (kein Download in den Standard Download-Ordner). Der Dateiname ist meines Erachtens korrekt, der von mir verwendete URL-Link wohl nicht, da die Datei wohl erst nach Bestätigung des Benutzers erstellt wird (mit Hilfe von Javascript?).
Hier der Code:
Sub DataUpdate()
Application.ScreenUpdating = False
wbDir = ActiveWorkbook.Path
wbAE = ActiveWorkbook.Name
Dim wbArr(3)
wbArr(1) = "ABGERUFENE_MRL_BETR_SOLL-WERTE.CSV"
wbArr(2) = "ABGERUFENE_SRL_BETR_IST-WERTE.CSV"
wbArr(3) = "RZ_SALDO_BETR_IST-WERTE_"
Dim startdate As Date
Dim startyear As String
Dim startmonth As String
Dim startday As String
Dim enddate As Date
Dim endyear As String
Dim endmonth As String
Dim endday As String
Dim tradedate As Date
Dim currentdate As Date
Dim currentyear As String
Dim currentmonth As String
Dim currentday As String
Dim SearchRng As Range
Dim FirstRow As Integer
Dim LastRow As Integer
currentdate = Workbooks(wbAE).Worksheets("test").Range("E9")
currentyear = Format(Year(currentdate), "0000")
currentmonth = Format(Month(currentdate), "00")
currentday = Format(Day(currentdate), "00")
today = currentyear & currentmonth & currentday
hours = Format(Hour(Now), "00")
minutes = Format(Minute(Now), "00")
seconds = Format(Second(Now), "00")
DownloadTime = hours & minutes & seconds
startdate = Workbooks(wbAE).Worksheets("test").Range("E11")
startyear = Format(Year(startdate), "0000")
startmonth = Format(Month(startdate), "00")
startday = Format(Day(startdate), "00")
Start = startyear & startmonth & startday
enddate = Workbooks(wbAE).Worksheets("test").Range("E12")
endyear = Format(Year(enddate), "0000")
endmonth = Format(Month(enddate), "00")
endday = Format(Day(enddate), "00")
last = endyear & endmonth & endday
For i = 3 To 3
DownloadFile = wbArr(i) & Start & "_" & last & "_Netzregelverbund_" & _ today & "-" & _
DownloadTime & ".CSV"
Url = "https://www.regelleistung.net/ext/data/" & DownloadFile
LocalFilename = wbDir & "\" & DownloadFile
x = URLDownloadToFile(0, Url, LocalFilename, 0, 0) = 0
Next i
Application.ScreenUpdating = True
End Sub
Danke für jegliche Hilfe im Voraus.