DefVar E
Function tcmb(ByVal Tarih As Date, ByVal Dovtip As String, ByVal Tipi As Long) As Variant
Dim gun As String, ay As String, yil As String, path As String, kur As Double
Dim icerik As String, xmlhttp As Object, sorgu As Variant
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
Application.Volatile
Dovtip = UCase(Dovtip)
gun = Day(Tarih): ay = Month(Tarih): yil = Year(Tarih)
If Len(gun) = 1 Then gun = "0" & gun
If Len(ay) = 1 Then ay = "0" & ay
path = "https://www.tcmb.gov.tr/kurlar/" & yil & ay & "/" & gun & ay & yil & ".xml"
xmlhttp.Open "GET", path, False
xmlhttp.send "at"
If xmlhttp.Status = 200 Then
icerik = xmlhttp.responseText
temizlik = Split(icerik, "<Currency CrossOrder=")
For y = 0 To UBound(temizlik)
If temizlik(y) Like "*=""" & Dovtip & "*" Then
sonuclar = Split(temizlik(y), "</CurrencyName>")
sorgu1 = Split(sonuclar(1), "<ForexBuying>")
sorgu2 = Split(sonuclar(1), "<ForexSelling>")
sorgu3 = Split(sonuclar(1), "<BanknoteBuying>")
sorgu4 = Split(sonuclar(1), "<BanknoteSelling>")
Select Case Tipi
Case 1: sorgu = Split(sorgu1(1), "</")
Case 2: sorgu = Split(sorgu2(1), "</")
Case 3: sorgu = Split(sorgu3(1), "</")
Case 4: sorgu = Split(sorgu4(1), "</")
End Select
Exit For
End If
Next y
End If
tcmb = Replace(sorgu(0), ".", ",")
End Function