Option
Explicit
Dim
Wert
As
Double
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
Public
Sub
main()
If
download_file <> 0
Then
MsgBox
"Problem beim herunterladen."
, vbExclamation
Exit
Sub
End
If
Wert = 0
Call
einlesen_und_durchschnitt
MsgBox
"Der Durchschnittswert liegt bei "
& Round(Wert / 21, 6), vbInformation
End
Sub
Private
Function
download_file()
As
Long
Dim
strURL
As
String
Dim
strLocalFile
As
String
strLocalFile = ThisWorkbook.Path &
"\Bitcoin_"
& Format(
Date
,
"YYYYMMDD"
) &
".csv"
download_file = URLDownloadToFile(0, strURL, strLocalFile, 0, 0)
End
Function
Private
Sub
einlesen_und_durchschnitt()
Dim
fso
As
Object
Dim
txtStream
As
Object
Dim
i
As
Integer
: i = 0
Dim
strPfad
As
String
Dim
strDaten()
As
String
strPfad = ThisWorkbook.Path &
"\Bitcoin_"
& Format(
Date
,
"YYYYMMDD"
) &
".csv"
Set
fso = CreateObject(
"Scripting.FilesystemObject"
)
Set
txtStream = fso.OpenTextfile(strPfad)
Do
While
Not
txtStream.AtEndOfStream
And
i < 22
If
i = 0
Then
txtStream.SkipLine
Else
strDaten() = Split(txtStream.ReadLine,
","
)
Wert = Wert +
CDbl
(Replace(strDaten(4),
"."
,
","
))
End
If
i = i + 1
Loop
txtStream.Close
Set
txtStream =
Nothing
Set
fso =
Nothing
End
Sub