Importer fichier Excel dans Outlook

Importer fichier Excel dans Outlook - VB/VBA/VBS - Programmation

Marsh Posté le 16-11-2007 à 11:12:41    

Bonjour,
 
Je souhaiterais importer un fichier Excel comprennant mes contacts dans Outlook mais de façon automatiser via une macro VBA auquel je lui donne le chemin vers le fichier Excel. Je suis en train d'écumé le web mais je ne trouve que des export de contact de Outlook vers Excel et non l'import Excel vers Outlook :(
Une petite aide est donc la bienvenue.
 
Merci d'avance
 
Groskachou

Reply

Marsh Posté le 16-11-2007 à 11:12:41   

Reply

Marsh Posté le 16-11-2007 à 12:24:08    

Bon j'ai tatonné en bidouillant ligne par ligne et voici le résultat:
 

Code :
  1. Sub test()
  2.     Dim exlApp As Excel.Application
  3.     Dim exlWkb As workbook
  4.     Dim exlsht As worksheet
  5.     Dim itmContact As Outlook.ContactItem
  6.     Set exlApp = New Excel.Application
  7.     strFilepath = exlApp.GetOpenFilename
  8.     If strFilepath = False Then
  9.         exlApp.Quit
  10.         Set exlApp = Nothing
  11.         Exit Sub
  12.     End If
  13.     Set exlsht = Excel.Application.Workbooks.Open(strFilepath).Worksheets(1)
  14.     Dim iRow As Integer
  15.     Dim iCol As Integer
  16.     Dim mpiFolder As MAPIFolder
  17.     Dim oNs As NameSpace
  18.     Set oNs = Outlook.GetNamespace("MAPI" )
  19.     Set mpiFolder = oNs.GetDefaultFolder(olFolderContacts)
  20.    
  21.     iRow = 2
  22.     iCol = 2
  23.     Set itmContact = Outlook.CreateItem(olContactItem)
  24.     itmContact.FirstName = exlsht.Cells(iRow, iCol)
  25.     itmContact.Save
  26.     Excel.Application.Workbooks.Close
  27.     exlApp.Quit
  28.     Set exlApp = Nothing
  29. End Sub


 
En tout cas, ca fait ce que je veux donc c'est niquel.


Message édité par groskachou le 16-11-2007 à 12:26:45
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed