Type VCF
Nom As String
PNom As String
FN As String
TEL As String
EMAIL As String
ADR As String
Cp As String
Ville As String
End Type
Property Get GetFichier(Optional Filter = "*.*") As String
With CreateObject("MSComDlg.CommonDialog")
.Filter = Filter
.ShowOpen
GetFichier = .Filename
End With
End Property
Property Get GetVCARD(Fichier) As String
Dim Exist As Boolean
With CreateObject("Scripting.FileSystemObject")
If Not .FileExists(Fichier) Then Exit Property
With .OpenTextFile(Fichier)
GetVCARD = .ReadAll
.Close
End With
End With
End Property
Sub test()
Dim Fichier As String, txt, Vcards() As VCF, Nb As Integer, I As Integer
Fich = GetFichier("VCARD Files (*.vcf)|*.vcf")
If Fich = "" Then Exit Sub
txt = Split(GetVCARD(Fich), "VCARD")
For I = 1 To UBound(txt) Step 2
ReDim Preserve Vcards(Nb)
Vcard txt(I), Vcards(Nb)
Nb = Nb + 1
Next
For I = 0 To UBound(Vcards)
Debug.Print Vcards(I).Nom, Vcards(I).PNom, Vcards(I).FN, Vcards(I).ADR, Vcards(I).Cp, Vcards(I).Ville, Vcards(I).TEL, Vcards(I).EMAIL
Next
End Sub
Sub Vcard(ByVal txt, ByRef card As VCF)
txt = Split(txt, Chr(10))
For I = 0 To UBound(txt)
If Mid(txt(I), 1, 2) = "N:" Then
Mid(txt(I), 1, 2) = " "
card.Nom = Trim(Split(txt(I), ";")(0))
card.PNom = Trim(Split(txt(I), ";")(1))
End If
If Mid(txt(I), 1, 3) = "FN:" Then
Mid(txt(I), 1, 3) = " "
card.FN = Trim(txt(I))
End If
If Mid(txt(I), 1, Len("TEL;WORK;VOICE:")) = "TEL;WORK;VOICE:" Then
Mid(txt(I), 1, Len("TEL;WORK;VOICE:")) = Space(Len("TEL;WORK;VOICE:"))
card.TEL = Trim(txt(I))
End If
If Mid(txt(I), 1, Len("EMAIL;INTERNET:")) = "EMAIL;INTERNET:" Then
Mid(txt(I), 1, Len("EMAIL;INTERNET:")) = Space(Len("EMAIL;INTERNET:"))
card.EMAIL = Trim(txt(I))
End If
If Mid(txt(I), 1, Len("ADR;TYPE=WORK:;;")) = "ADR;TYPE=WORK:;;" Then
Mid(txt(I), 1, Len("ADR;TYPE=WORK:;;")) = Space(Len("ADR;TYPE=WORK:;;"))
card.ADR = Trim(txt(I))
End If
Next
EclateAdresse card
End Sub
Sub EclateAdresse(Vcard As VCF)
Dim T() As String, c As Integer, I As Integer
T() = Split(Vcard.ADR)
Vcard.ADR = ""
For I = UBound(T) To 0 Step -1
If IsNumeric(T(I)) Then c = c + 1
If c = 1 And Not IsNumeric(T(I)) Then c = c + 1
Select Case c
Case 0
Vcard.Ville = Trim(T(I) & " " & Vcard.Ville)
Case 1
Vcard.Cp = Trim(T(I) & " " & Vcard.Cp)
Case Else
Vcard.ADR = Trim(T(I) & " " & Vcard.ADR)
End Select
Next
End Sub