rebol [ Title: "Outlook Contacts" File: %outlook-contacts.r Date: 13-Dec-2005 Version: 1.0.1 Progress: 0.5 Status: "working" Needs: [] Author: "Anton Rolls" Language: "English" Purpose: {Print full name of each contact in Outlook's contact list.} Usage: {} History: [ 1.0.0 [13-Dec-2005 {First version} "Anton"] 1.0.1 [9-Jul-2006 {revised for reengineered COMLib} "Anton"] ] ToDo: { - My last contact is a distribution list, so there was an error when I tried to print FullName - find a way to list the Properties of an object - or at least a way to list the Members of a ContactItem - perhaps try to save the default Folder ? (don't think so..) - investigate -> ContactItem.SaveAs(path, [type]) - discover the default type (looks like default is 3 = MSG) } Notes: { Contacts example successfully derived from: http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips0517.mspx http://www.outlookcode.com/d/tips/gethelp.htm 1. Press Alt+F11 to open the VBA environment. 2. Press F2 to display the Object Browser. 3. If you're in Word or Excel VBA, choose Tools | References, and add the Microsoft Outlook library to the project. 4. At the top of the Object Browser, switch from viewing to Outlook. http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips0517.mspx http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_ol2003_bk/html/odc_olArticleUsingVBAInOutlook.asp Outlook Object Model Overview http://msdn2.microsoft.com/en-us/library/ms268893.aspx http://www.outlookcode.com/d/outtech.htm SaveAsType http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol11/html/olmthSaveAs_HV05247719.asp } ] if error? set/any 'error try [ ; catch all errors do/args %../COMLib.r [ ; Use the COMLib API functions here outlook-app: CreateObject "Outlook.Application" ; bind to the current instance of Outlook (assumed to be already running) wait 0.1 outlook-ns: GetObject [outlook-app ".GetNamespace(%s)" "MAPI"] wait 0.1 ; Set cf = olns.GetDefaultFolder(olFolderContacts) ; Set objItems = cf.Items ; iNumContacts = objItems.Count olFolderContacts: 10 contactsFolder: GetObject [outlook-ns ".GetDefaultFolder(%d)" olFolderContacts] Contacts: EnumBegin [contactsFolder ".Items"] ; a collection of Contacts while [not zero? Contact: EnumNextObject [Contacts]][ wait 0.1 print ["Class:" class: GetInteger [Contact ".Class"]] ; OlObjectClass switch class [ 40 [ ; olContact = 40 print [tab FullName: GetString [Contact ".FullName"]] ; ".CompanyName" if "Anton Rolls" = FullName [ ;print "saving contact...." ;;CallMethod [Contact ".SaveAs(%s,%m)" "D:\outlook-contact.dat"] ; <-- this works ;CallMethod [Contact ".SaveAs(%s,%d)" "D:\outlook-contact.txt" 0] ; <-- this works ;;CallMethod [Contact ".SaveAs(%s,%d)" "D:\outlook-contact.msg" 3] ; looks like the default ? ;OlSaveAsType ; olTXT = 0 ; olRTF = 1 ; olTemplate = 2 ; olMSG = 3 ; olDoc = 4 ; olHTML = 5 ; olVCard = 6 ; olVCal = 7 ] ] 69 [ ; olDistributionList = 69 print "<--- DistributionList" ;print "saving DistList..." ;;CallMethod [Contact ".SaveAs(%s,%m)" "D:\outlook-contact.dat"] ; <-- this works ;CallMethod [Contact ".SaveAs(%s,%d)" "D:\outlook-distlist.txt" 0] ; <-- this works ] ] release Contact ] release Contacts release contactsFolder release outlook-ns release outlook-app ] ][ print mold disarm error ]