{"id":990,"date":"2012-01-08T21:20:31","date_gmt":"2012-01-08T15:50:31","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=990"},"modified":"2012-01-08T21:21:46","modified_gmt":"2012-01-08T15:51:46","slug":"automating-outlook-using-qtp-working-with-outlook-contacts","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/","title":{"rendered":"Part 4: Automating Outlook using QTP | Working with Outlook Contacts"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Verdana;\">\n<p>In this article, you&#8217;ll see how you can work with Outlook Contacts. We&#8217;ll cover various topics such as how to access Outlook Contacts, how to retrieve properties (such as name, telephone number, email id etc) from an Outlook Contact, how to search for a Contact, how to create a new Contact, delete a Contact etc.<!--more--><\/p>\n<p><strong>In Outlook, Contact Items are stored in Contacts folder and it is represented by ContactItem object.<\/strong> ContactItem objects contain a variety of contact information, such as people&#8217;s street addresses, e-mail addresses, and phone numbers. It also provides a set of methods using which you can access Outlook Contacts. Let&#8217;s see few examples on how to work with Outlook Contacts.<br \/>\n<span><br \/>\n<\/span><br \/>\n<strong> Sample Code 1: Access Outlook Contacts and display details of a Contact.<\/strong> Here the script accesses contact items from Contacts folder and displays the details of the first contact.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim sMessage\r\nsMessage = &quot;&quot;\r\n\r\nSet objOutlook = CreateObject(&quot;Outlook.Application&quot;)\r\nSet objNamespace = objOutlook.GetNamespace(&quot;MAPI&quot;)\r\n\r\n'Create reference to Contacts Folder\r\nSet oContacts = objNamespace.GetDefaultFolder(10)\r\n\r\n'Find all items in the Contacts Folder\r\nSet oAllContacts = oContacts.Items\r\niCount = oAllContacts.Count\r\nsMessage = &quot;Total Contacts -&gt; &quot; &amp; iCount &amp; vbCrLf &amp; vbCrLf\r\n\r\n'Find out different properties of the first contact\r\nIf iCount &gt;= 1 Then\r\n\tsMessage = sMessage &amp; &quot;Full Name - &quot; &amp; oAllContacts(1).FullName &amp; vbCrLf\r\n\tsMessage = sMessage &amp; &quot;Company - &quot; &amp; oAllContacts(1).CompanyName &amp; vbCrLf\r\n\tsMessage = sMessage &amp; &quot;Job Title - &quot; &amp; oAllContacts(1).JobTitle &amp; vbCrLf\r\n\tsMessage = sMessage &amp; &quot;File As - &quot; &amp; oAllContacts(1).FileAs &amp; vbCrLf\r\n\tsMessage = sMessage &amp; &quot;Email - &quot; &amp; oAllContacts(1).Email1Address &amp; vbCrLf\r\n\tsMessage = sMessage &amp; &quot;Display As - &quot; &amp; oAllContacts(1).Email1DisplayName &amp; vbCrLf\r\n\tsMessage = sMessage &amp; &quot;Web Page - &quot; &amp; oAllContacts(1).WebPage &amp; vbCrLf\r\nEnd If\r\n'Display the contact properties\r\nmsgbox sMessage\r\n<\/pre>\n<div style=\"width: 822px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"Access Outlook Contact Details\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png\" alt=\"Access Outlook Contact Details\" width=\"812\" height=\"423\" \/><p class=\"wp-caption-text\">Access Outlook Contact Details<\/p><\/div>\n<p><span><br \/>\n<\/span><br \/>\n<strong>Sample Code 2: Create a new Outlook Contact.<\/strong> This example creates a new Outlook Contact and displays it.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim olContactItem\r\n'olContactItem is Referenced by Value 2\r\nolContactItem = 2\r\n\r\nSet objOutlook = CreateObject(&quot;Outlook.Application&quot;)\r\nSet oNewContact = objOutlook.CreateItem(2)\r\n\r\n'Set Properties for the new Contact\r\noNewContact.FirstName = &quot;First&quot;\r\noNewContact.LastName = &quot;Last&quot;\r\noNewContact.Email1Address = &quot;first@email.com&quot;\r\noNewContact.CustomerID = &quot;123456&quot;\r\noNewContact.PrimaryTelephoneNumber = &quot;(91)0000000000&quot;\r\noNewContact.MailingAddressStreet = &quot;Street&quot;\r\noNewContact.MailingAddressCity = &quot;City&quot;\r\noNewContact.MailingAddressState = &quot;State&quot;\r\n\r\n'Save details and display\r\noNewContact.Save\r\noNewContact.Display\r\n<\/pre>\n<div style=\"width: 730px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" title=\"Create New Outlook Contact\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/new-outlook-contact.png\" alt=\"Create New Outlook Contact\" width=\"720\" height=\"436\" \/><p class=\"wp-caption-text\">Create New Outlook Contact<\/p><\/div>\n<p><span><br \/>\n<\/span><br \/>\n<strong>Sample Code 3: Copy an Existing Outlook Contact.<\/strong> This example searches for a contact with a specific mail id and then creates a copy of the same.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim iCount, objReturnVal\r\n\r\nSet objOutlook = CreateObject(&quot;Outlook.Application&quot;)\r\nSet objNamespace = objOutlook.GetNamespace(&quot;MAPI&quot;)\r\n\r\n'Create reference to Contacts Folder\r\nSet oContacts = objNamespace.GetDefaultFolder(10)\r\n\r\n'Find all items in the Contacts Folder\r\nSet oAllContacts = oContacts.Items\r\niCount = oAllContacts.Count\r\n\r\n'Copy an existing contact\r\nFor i=1 to iCount\r\n  If oAllContacts(i).Email1Address = &quot;abc@email.com&quot; Then\r\n    'objReturnVal is the object that contains the copied Contact\r\n    Set objReturnVal = \toAllContacts(i).Copy\r\n    Exit For\r\n  End If\r\nNext\r\n\r\n'Display Results\r\nmsgbox &quot;Contact Copied. Full Name -&gt; &quot; &amp; objReturnVal.FullName\r\n<\/pre>\n<p><span><br \/>\n<\/span><br \/>\n<strong>Sample Code 4: Delete an Outlook Contact.<\/strong> This example deletes an Outlook Contact based on a specific criteria<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSet objOutlook = CreateObject(&quot;Outlook.Application&quot;)\r\nSet objNamespace = objOutlook.GetNamespace(&quot;MAPI&quot;)\r\n\r\n'Create reference to Contacts Folder\r\nSet oContacts = objNamespace.GetDefaultFolder(10)\r\n\r\n'Find all items in the Contacts Folder\r\nSet oAllContacts = oContacts.Items\r\niCount = oAllContacts.Count\r\n\r\nFor i = 1 to iCount\r\n  If oAllContacts(i).Email1Address = &quot;abc@email.com&quot; Then\r\n    oAllContacts(i).Delete\r\n    Exit For\r\n  End If\r\nNext\r\n<\/pre>\n<\/div>\n<p><span><br \/>\n<\/span><\/p>\n<p style=\"border: 1px solid #C38EC7; padding: 3mm; background: #EBDDE2;\">If you feel that we have missed out any important concept, or if you want any other topic to be covered here, please leave a comment or just drop in a mail to us. We&#8217;ll be more than happy to work on it.<\/p>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p>If you enjoyed this article, you can join our blog to get new posts delivered directly in your inbox.<\/p>\n<form style=\"text-align: center;\" action=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify\" method=\"post\" onsubmit=\"window.open('http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=automationrepository\/feeds', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\" target=\"popupwindow\"><input style=\"width: 160px; height: 20px;\" onfocus=\"if (this.value == 'Enter Your Email Address') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Enter Your Email Address';}\" type=\"text\" value=\"Enter Your Email Address\" \/> <input type=\"hidden\" name=\"uri\" value=\"automationrepository\/feeds\" \/> <input type=\"hidden\" name=\"loc\" value=\"en_US\" \/> <input type=\"submit\" value=\"Join Us\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n<p><span><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, you&#8217;ll see how you can work with Outlook Contacts. We&#8217;ll cover various topics such as how to access Outlook Contacts, how to retrieve properties (such as name, telephone number, email id etc) from an Outlook Contact, how to search for a Contact, how to create a new Contact, delete a Contact etc.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,9],"tags":[54],"class_list":["post-990","post","type-post","status-publish","format-standard","hentry","category-advanced-concepts","category-qtp-concepts","tag-automating-outlook-using-qtp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Part 4: Automating Outlook | Working with Outlook Contacts<\/title>\n<meta name=\"description\" content=\"Read how to access Outlook Contacts, how to retrieve properties (such as name, telephone number, email id etc) from an Outlook Contact, how to search for a Contact, how to create a new Contact, delete a Contact etc.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anish Pillai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/\",\"name\":\"Part 4: Automating Outlook | Working with Outlook Contacts\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png\",\"datePublished\":\"2012-01-08T15:50:31+00:00\",\"dateModified\":\"2012-01-08T15:51:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"description\":\"Read how to access Outlook Contacts, how to retrieve properties (such as name, telephone number, email id etc) from an Outlook Contact, how to search for a Contact, how to create a new Contact, delete a Contact etc.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Part 4: Automating Outlook using QTP | Working with Outlook Contacts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/\",\"name\":\"XX\",\"description\":\"\\r\\nasas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\",\"name\":\"Anish Pillai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"caption\":\"Anish Pillai\"},\"description\":\"Find more about Anish Pillai on Google+\",\"sameAs\":[\"http:\/\/www.automationrepository.com\"],\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Part 4: Automating Outlook | Working with Outlook Contacts","description":"Read how to access Outlook Contacts, how to retrieve properties (such as name, telephone number, email id etc) from an Outlook Contact, how to search for a Contact, how to create a new Contact, delete a Contact etc.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/","name":"Part 4: Automating Outlook | Working with Outlook Contacts","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png","datePublished":"2012-01-08T15:50:31+00:00","dateModified":"2012-01-08T15:51:46+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"description":"Read how to access Outlook Contacts, how to retrieve properties (such as name, telephone number, email id etc) from an Outlook Contact, how to search for a Contact, how to create a new Contact, delete a Contact etc.","breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/outlook-contact-details.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/01\/automating-outlook-using-qtp-working-with-outlook-contacts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Part 4: Automating Outlook using QTP | Working with Outlook Contacts"}]},{"@type":"WebSite","@id":"https:\/\/www.automationrepository.com\/wordpress\/#website","url":"https:\/\/www.automationrepository.com\/wordpress\/","name":"XX","description":"\r\nasas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20","name":"Anish Pillai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","caption":"Anish Pillai"},"description":"Find more about Anish Pillai on Google+","sameAs":["http:\/\/www.automationrepository.com"],"url":"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/"}]}},"_links":{"self":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/comments?post=990"}],"version-history":[{"count":9,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/990\/revisions"}],"predecessor-version":[{"id":998,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/990\/revisions\/998"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}