Function numTel(ByVal num As String, Optional valide As Boolean = False) As String
' valide = False : n° non reconnu inchangé
' valide = True : n° non reconnu mis à ""
'
Const prefixeInt = "00" ' ou "+", sert uniquement pour le format retourné
' Plans de num pays Grèce,Mayotte,Andorre,Monaco,Luxembourg
Const codeInt As String = "30,262,376,377,352"
Const lNumInt As String = "10,6,6,8,4-11" ' nombre de chiffres plan de num du pays
'
Dim datas, lig As Long, b_fr As Boolean, b_int As Boolean
Dim ci, planNum(), i As Long, tmp
' table plan num international
ci = Split(codeInt, ",")
tmp = Split(lNumInt, ",")
ReDim planNum(0 To UBound(tmp), 1 To 2)
For i = 0 To UBound(tmp)
If InStr(tmp(i), "-") > 0 Then ' plage
planNum(i, 1) = CLng(Split(tmp(i), "-")(0)): planNum(i, 2) = CLng(Split(tmp(i), "-")(1))
Else
planNum(i, 1) = CLng(tmp(i)): planNum(i, 2) = CLng(tmp(i))
End If
Next i
num = Replace(Replace(Replace(Replace(num, " ", ""), ".", ""), "-", ""), ",", "")
num = Replace(num, "(0)", "")
If Left(num, 1) = "+" Then num = "00" & Mid(num, 2)
If Left(num, 4) = "0033" Then
num = Right(num, 9): b_fr = True
ElseIf Left(num, 2) = "00" Then
num = Mid(num, 3): b_int = True
End If
i = 1
Do While Mid(num, i, 1) = "0": i = i + 1: Loop ' compter zéros du début
' normaliser n° national
If Not b_int Then If Len(num) - i + 1 = 9 Or (Len(num) = 11 And Left(num, 2) = "33") Then num = Right(num, 9): b_fr = True
If b_fr Then ' national
Select Case Left(num, 1)
Case "6", "7" ' mobiles
num = prefixeInt & "33-" & num
Case Else ' régionaux
num = Format(Val(num), prefixeInt & """33-""#-########")
End Select
Else
' n° international reconnu ?
For i = 0 To UBound(ci) ' recherche code pays
If Left(num, Len(ci(i))) = ci(i) Then
If Len(num) >= Len(ci(i)) + Val(planNum(i, 1)) And Len(num) <= Len(ci(i)) + Val(planNum(i, 2)) Then
num = prefixeInt & ci(i) & "-" & Mid(num, Len(ci(i)) + 1)
ElseIf valide Then
num = vbNullString: Exit For
End If
Exit For
End If
Next i
If i > UBound(ci) And valide Then num = vbNullString
End If
numTel = num
End Function