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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
Sub ActualiserContactsOutlookDepuisExcelSharePoint()
' Configuration SharePoint
Dim sharepointSiteURL As String
Dim sharepointFilePath As String
Dim excelFileName As String
Dim excelSheetName As String
sharepointSiteURL = "https://your-sharepoint-site-url.com"
sharepointFilePath = "/Shared Documents/Folder/ExcelFile.xlsx"
excelFileName = "ExcelFile.xlsx"
excelSheetName = "Sheet1"
' Configuration Outlook
Dim objOutlook As Object
Dim objNamespace As Object
Dim objContactsFolder As Object
Dim objContactGroup As Object
Dim objContact As Object
' Obtenir une référence à Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
' Obtenir une référence au dossier des contacts
Set objContactsFolder = objNamespace.GetDefaultFolder(10)
' Nom du dossier "Contacts"
Dim contactsFolderName As String
contactsFolderName = "Contacts"
' Nom du groupe de contacts à accéder
Dim groupName As String
groupName = "groupe1"
' Parcourir les dossiers de contacts pour trouver le dossier "Contacts"
Dim contactsFolder As Object
For Each contactsFolder In objContactsFolder.Folders
If contactsFolder.Name = contactsFolderName Then
' Parcourir les groupes de contacts dans le dossier "Contacts" pour trouver le groupe spécifié
For Each objContactGroup In contactsFolder.Folders
If objContactGroup.Name = groupName Then
' Le groupe de contacts spécifié a été trouvé
' Ouvrir le fichier Excel dans SharePoint
Dim excelApp As Object
Dim excelWorkbook As Object
Dim excelWorksheet As Object
Dim rngData As Object
Dim rngRow As Object
' Créer une instance de l'application Excel
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = False
excelApp.Workbooks.Open (sharepointSiteURL & sharepointFilePath)
Set excelWorkbook = excelApp.Workbooks(excelFileName)
Set excelWorksheet = excelWorkbook.Worksheets(excelSheetName)
' Récupérer la plage de données à partir de la feuille Excel
Set rngData = excelWorksheet.Range("A2:C" & excelWorksheet.Cells(excelWorksheet.Rows.Count, 1).End(-4162).Row)
' Parcourir les lignes de données
For Each rngRow In rngData.Rows
Dim strEmailAddress As String
' Récupérer l'adresse e-mail de la cellule dans la colonne A
strEmailAddress = rngRow.Cells(1).Value
' Vérifier si l'adresse e-mail est non vide
If Not IsEmpty(strEmailAddress) Then
' Rechercher le contact correspondant dans le groupe de contacts
Set objContact = objContactGroup.Items.Find("[Email1Address] = '" & strEmailAddress & "'")
' Vérifier si le contact a été trouvé
If Not objContact Is Nothing Then
' Modifier les propriétés du contact avec les données de la ligne Excel
objContact.FirstName = rngRow.Cells(2).Value
objContact.LastName = rngRow.Cells(3).Value
objContact.Email1Address = strEmailAddress
' Enregistrer les modifications
objContact.Save
End If
End If
Next rngRow
' Fermer le classeur Excel et l'application Excel
excelWorkbook.Close SaveChanges:=False
excelApp.Quit
' Nettoyer les objets Excel
Set rngData = Nothing
Set rngRow = Nothing
Set excelWorksheet = Nothing
Set excelWorkbook = Nothing
Set excelApp = Nothing
Exit For
End If
Next objContactGroup
Exit For
End If
Next contactsFolder
' Terminer Outlook
Set objContact = Nothing
Set objContactGroup = Nothing
Set objContactsFolder = Nothing
Set objNamespace = Nothing
Set objOutlook = Nothing
MsgBox "Les contacts dans le groupe de contacts 'KKG-groupe2' ont été mis à jour à partir du fichier Excel SharePoint.", vbInformation
End Sub |
Partager