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 à ""
'
' Plans de num pays Mayotte,Andorre,Monaco
Const codeInt As String = "262,376,377"
Const lNumInt As String = "6,6,8" ' 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
num = Replace(Replace(Replace(Replace(num, " ", ""), ".", ""), "-", ""), ",", "")
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 = "0033-" & num
Case Else ' régionaux
num = Format(Val(num), """0033-""#-########")
End Select
Else
' n° international reconnu ?
ci = Split(codeInt, ",")
planNum = Split(lNumInt, ",")
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)) Then
num = "00" & ci(i) & "-" & Mid(num, Len(ci(i)) + 1)
Exit For
ElseIf valide Then
num = vbNullString: Exit For
End If
End If
Next i
If i > UBound(ci) And valide Then num = vbNullString
End If
numTel = num
End Function