WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE and Outlook
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Import Excel Data into Outlook Contact Folder


xlsfile   = "C:\Temp\Data\Contactlist.xls"
;Example - Format of XLS File
;     Column 1 = First name
;     Column 2 = Last name
;     Column 3 = Email address
;     Etc.


;Define Outlook Constants
olFolderContacts = 10

;Find contact folder, assign to object variable
objOL = ObjectCreate("Outlook.Application")
objNS = objOL.GetNamespace("MAPI")
objFolder = objNS.GetDefaultFolder(olFolderContacts)
objFolder.Display

;Open Excel
objXL = ObjectOpen("Excel.Application")
;objXL.Visible = @TRUE
objXL.UserControl = @TRUE

oAPP = objXL.Workbooks
oAPP.Open(xlsfile)
oACT = objXL.ActiveWorkbook
oWS  = objXL.Worksheets(1)

FirstRow = 1
LastRow = oWS.UsedRange.Rows(oWS.UsedRange.Rows.Count).Row

;Loop down worksheet rows
For r = FirstRow To LastRow    
   ;Add new contact, set to object variable
   objContact = objFolder.Items.Add   
   ;Set contact properties
   objContact.FirstName = oWS.Cells(r, 1).value
   objContact.LastName = oWS.Cells(r, 2).value
   objContact.Email1Address = oWS.Cells(r, 3)
   ; Etc.
   ;(set more properties here)
   objContact.Save()
   objContact = 0
Next 



;destroy objects to clean up memory
objFolder = 0
objNS = 0
objOL.Quit()
objOL = 0

oWS = 0
oACT = 0
oAPP = 0
objXL.Quit()
objXL = 0




Article ID:   W17128
File Created: 2007:07:03:14:28:24
Last Updated: 2007:07:03:14:28:24