Public Function extractionValeur(codeAction As String)
Dim url As String
Dim masque As String
Dim txt As String
Dim i As Double
Dim val As Double
Dim tmp As String
Dim tmp1 As String
Dim IsMySeparatorAComma As Boolean
IsMySeparatorAComma = CInt("0,1") = 0 ' True if "," is separator
Const NUMERIC_CHARS = "0123456789.,"
If codeAction = "FTSE" Then
url = "http://www.boursorama.com/cours.phtml?symbole=UKX.L"
Else
If codeAction = "SP500" Then
url = "http://www.boursorama.com/cours.phtml?symbole=%24INX"
Else
MsgBox ("Code inexistant")
Exit Sub
End If
End If
'Creation of a mask before action value (in html code source page)
If codeAction = "FTSE" Then
masque = ""
Else
masque = ""
End If
'Get source code in variable txt
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", url, False
.Send
txt = .ResponseText
End With
Do
'Return the mask position in the txt variable
i = InStr(i + 1, txt, masque)
If i = 0 Then Exit Do
'Stock share value (4 Digits) in the variable
tmp = Mid$(txt, i + Len(masque), 7)
Loop
For lThisChar = 1 To Len(tmp)
If InStr(1, NUMERIC_CHARS, Mid$(tmp, lThisChar, 1)) > 0 Then
'Found a numeric character
tmp1 = tmp1 & Mid$(tmp, lThisChar, 1)
End If
Next lThisChar
If Not IsMySeparatorAComma Then
tmp1 = Replace(tmp1, ",", ".")
End If
extractionValeur = tmp1
End Function