{"id":69,"date":"2017-03-24T20:04:52","date_gmt":"2017-03-24T20:04:52","guid":{"rendered":"http:\/\/www.polysyncronism.com\/wordpress\/?p=69"},"modified":"2017-03-24T20:04:52","modified_gmt":"2017-03-24T20:04:52","slug":"outlook-search-with-wildcard","status":"publish","type":"post","link":"http:\/\/www.polysyncronism.com\/wordpress\/2017\/03\/24\/outlook-search-with-wildcard\/","title":{"rendered":"Outlook Search with Wildcard"},"content":{"rendered":"<p>This post was inspired by a\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/21549938\/vba-search-in-outlook\" target=\"_blank\">stackoverflow \u2013 VBA Search in Outlook<\/a>\u00a0question.<\/p>\n<p>Here is an example that let\u2019s you do a wildcard search using the\u00a0<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb220369%28v=office.12%29.aspx\" target=\"_blank\">Items Restrict Method<\/a><\/p>\n<pre class=\"lang:vb decode:true \" title=\"Outlook VBA - Search with wildcard\">Option Explicit\r\n \r\nSub Search_Inbox()\r\n \r\nDim myOlApp As New Outlook.Application\r\nDim objNamespace As Outlook.NameSpace\r\nDim objFolder As Outlook.MAPIFolder\r\nDim filteredItems As Outlook.Items\r\nDim itm As Object\r\nDim Found As Boolean\r\nDim strFilter As String\r\n \r\n \r\nSet objNamespace = myOlApp.GetNamespace(\"MAPI\")\r\nSet objFolder = objNamespace.GetDefaultFolder(olFolderInbox)\r\n \r\nstrFilter = \"@SQL=\" &amp; Chr(34) &amp; \"urn:schemas:httpmail:subject\" &amp; Chr(34) &amp; \" like '%sketch%'\"\r\n \r\nSet filteredItems = objFolder.Items.Restrict(strFilter)\r\n \r\nIf filteredItems.Count = 0 Then\r\n    Debug.Print \"No emails found\"\r\n    Found = False\r\nElse\r\n    Found = True\r\n    ' this loop is optional, it displays the list of emails by subject.\r\n    For Each itm In filteredItems\r\n     Debug.Print itm.Subject\r\n    Next\r\nEnd If\r\n    \r\n \r\n'If the subject isn't found:\r\nIf Not Found Then\r\n    'NoResults.Show\r\nElse\r\n   Debug.Print \"Found \" &amp; filteredItems.Count &amp; \" items.\"\r\n    \r\nEnd If\r\n \r\n'myOlApp.Quit\r\nSet myOlApp = Nothing\r\n \r\nEnd Sub<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post was inspired by a\u00a0stackoverflow \u2013 VBA Search in Outlook\u00a0question. Here is an example that let\u2019s you do a wildcard search using the\u00a0Items Restrict Method Option Explicit Sub Search_Inbox() Dim myOlApp As New Outlook.Application Dim objNamespace As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim filteredItems As Outlook.Items Dim itm As Object Dim Found As Boolean &hellip; <a href=\"http:\/\/www.polysyncronism.com\/wordpress\/2017\/03\/24\/outlook-search-with-wildcard\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Outlook Search with Wildcard&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-code","category-vba"],"_links":{"self":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":1,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":70,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/posts\/69\/revisions\/70"}],"wp:attachment":[{"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.polysyncronism.com\/wordpress\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}