1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Function ContactsExiste(Nom_, Prenom_, Telephone_, Mail_, Adresse_ As String) As Integer
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
'Dim myItems As Outlook.Items*
Dim Cible As Outlook.ContactItem
Dim ol_OK As Integer
Set myolApp = CreateObject("Outlook.Application")
'Vérifie si Outlook est ouvert !!!!!!
If myolApp.Explorers.Count > 0 Then
'Debug.Print "Outlook est ouvert"
Else
'Debug.Print "Outlook n'est pas ouvert"
ol_OK = Shell("C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE", 3)
End If
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Items
For Each Cible In myContacts
'Debug.Print Cible.FirstName, Cible.LastName, Cible.User1, Cible.MobileTelephoneNumber, Cible.Email1Address, Cible.HomeAddress, Cible.Categories
If (Cible.LastName = Nom_) And (Cible.FirstName = Prenom_) And (Cible.MobileTelephoneNumber = Telephone_) And (Cible.Email1Address = Mail_) And (Cible.HomeAddress = Adresse_) Then
'Debug.Print Cible.FirstName, Cible.LastName, Cible.User1, Cible.MobileTelephoneNumber, Cible.Email1Address, Cible.HomeAddress, Cible.Categories
ContactsExiste = 2
Exit For
Else
If (Cible.LastName = Nom_) And (Cible.FirstName = Prenom_) Then
ContactsExiste = 1
'Debug.Print Cible.FirstName, Cible.LastName, Cible.User1, Cible.MobileTelephoneNumber, Cible.Email1Address, Cible.HomeAddress, Cible.Categories
Exit For
Else
ContactsExiste = 0
End If
End If
DoEvents
Next
Set myContacts = Nothing
Set myNamespace = Nothing
Set myolApp = Nothing
End Function |
Partager