{"id":55,"date":"2017-07-19T18:46:24","date_gmt":"2017-07-19T18:46:24","guid":{"rendered":"http:\/\/www.tolouautomation.com\/?p=55"},"modified":"2017-07-19T18:46:24","modified_gmt":"2017-07-19T18:46:24","slug":"debugging-ms-outlook-2010-vb-script-used-in-a-rule","status":"publish","type":"post","link":"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/","title":{"rendered":"Debugging MS Outlook 2010 VB script used in a rule"},"content":{"rendered":"<p>I wanted to run a VB script in MS-Outlook 2010, in a rule applied to every incoming messages, but I was\u00a0not sure what was the cause of the issue preventing it to run as I expected.<\/p>\n<p>It meant to find e-mails that\u00a0contain a desired word in its body, but in various upper\/lower letter combination, e.g. &#8220;Sometext&#8221;,\u00a0&#8220;sometext&#8221;, or &#8220;SOMETEXT&#8221;. Then make them &#8220;Unreaded&#8221; and then move them to &#8220;Deleted Items&#8221;\u00a0folder.<\/p>\n<p>So I tried the following way to pinpoint the point of error, as I was not able to find out a way to use the\u00a0debug option of VB (I am not quite sure if it is even possible).<\/p>\n<ol start=\"1\">\n<li>I added &#8220;On Error GoTo&#8221; statement to the VB script, to find out where and why \u00a0this error ever happen.<\/li>\n<li>I added an error &#8220;Handler&#8221; part to the VB script, and run the script against \u00a0some sample e-mails.<\/li>\n<li>Thanks to &#8220;<a href=\"https:\/\/www.fmsinc.com\/free\/newtips\/VBA\/ErrorHandling\/LineNumber.html\" target=\"_blank\" rel=\"noopener\">Pinpointing the Exact Line Where A Crash Occurs in VB6 or VBA<\/a>&#8221; that has made\u00a0<span style=\"font-size: 1rem;\">finding the line of error possible for me, using &#8220;Erl&#8221;, knowing where the error occurred is just to read the error message of the &#8220;MsgBox&#8221;.<\/span><\/li>\n<\/ol>\n<p>The following is the complete VB code. Pay attention to line numbers, in fact they are the trick to make &#8220;Erl&#8221; shows the error line number.<\/p>\n<p><code>Sub CheckSpam(Item As Outlook.MailItem)<\/code><br \/>\n<code>Dim deletedFolder As Outlook.Folder<\/code><br \/>\n<code><\/code><br \/>\n<code>10 On Error GoTo Handler<\/code><br \/>\n<code><\/code><br \/>\n<code>20 If InStr(LCase(Item.Body), \"sometext\") &gt; 0 Then ' \"sometext\" all in lower case<\/code><br \/>\n<code>30 Set deletedFolder = Application.GetNamespace(\"MAPI\"). _<\/code><br \/>\n<code>GetDefaultFolder(olFolderDeletedItems)<\/code><br \/>\n<code>40 Item.UnRead = False<\/code><br \/>\n<code>50 Item.Move (deletedFolder)<\/code><br \/>\n<code>60 Set deletedFolder = Nothing<\/code><br \/>\n<code>760 End If<\/code><br \/>\n<code>80 Exit Sub<\/code><br \/>\n<code>Handler:<\/code><br \/>\n<code>90 MsgBox \"Error Line: \" &amp; Erl &amp; vbCrLf &amp; _<\/code><br \/>\n<code>\"Error: (\" &amp; Err.Number &amp; \") \" &amp; Err.Description, vbCritical<\/code><br \/>\n<code>End Sub<\/code><\/p>\n<ol start=\"4\">\n<li>Then after running on sample e-mail message, I realized that line 50 give the following error:<\/li>\n<\/ol>\n<p>&#8220;Object is required&#8221;.<\/p>\n<ol start=\"5\">\n<li>By replacing line 50 with the following the issue has been removed.<\/li>\n<\/ol>\n<p><code>50 Item.Move deletedFolder<\/code><\/p>\n<p>I don&#8217;t know why the parenthesis should be removed but by looking at some examples I have realized that this is the cause of error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to run a VB script in MS-Outlook 2010, in a rule applied to every incoming messages, but I was\u00a0not sure what was the cause of the issue preventing it to run as I expected. It meant to find e-mails that\u00a0contain a desired word in its body, but in various upper\/lower letter combination, e.g. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Debugging MS Outlook 2010 VB script used in a rule&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[10,12,15,18],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-msoutlook","tag-debug","tag-msoutlook","tag-rule","tag-vbscript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Debugging MS Outlook 2010 VB script used in a rule - Afraz-sanat Zonouz<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Debugging MS Outlook 2010 VB script used in a rule - Afraz-sanat Zonouz\" \/>\n<meta property=\"og:description\" content=\"I wanted to run a VB script in MS-Outlook 2010, in a rule applied to every incoming messages, but I was\u00a0not sure what was the cause of the issue preventing it to run as I expected. It meant to find e-mails that\u00a0contain a desired word in its body, but in various upper\/lower letter combination, e.g. &hellip; Continue reading &quot;Debugging MS Outlook 2010 VB script used in a rule&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/\" \/>\n<meta property=\"og:site_name\" content=\"Afraz-sanat Zonouz\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-19T18:46:24+00:00\" \/>\n<meta name=\"author\" content=\"afrazsanat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"afrazsanat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/\",\"url\":\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/\",\"name\":\"Debugging MS Outlook 2010 VB script used in a rule - Afraz-sanat Zonouz\",\"isPartOf\":{\"@id\":\"https:\/\/afraz-sanat.com\/#website\"},\"datePublished\":\"2017-07-19T18:46:24+00:00\",\"author\":{\"@id\":\"https:\/\/afraz-sanat.com\/#\/schema\/person\/b9034d80592ca319227aafd344f9db69\"},\"breadcrumb\":{\"@id\":\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/afraz-sanat.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Debugging MS Outlook 2010 VB script used in a rule\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/afraz-sanat.com\/#website\",\"url\":\"https:\/\/afraz-sanat.com\/\",\"name\":\"Afraz-sanat Zonouz\",\"description\":\"Office and industrial Automation\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/afraz-sanat.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/afraz-sanat.com\/#\/schema\/person\/b9034d80592ca319227aafd344f9db69\",\"name\":\"afrazsanat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/afraz-sanat.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c9ffce4f6798f570d1cf6a2cb93fdc64123c9ea09b5c199fd12f25ed9a8a0a82?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c9ffce4f6798f570d1cf6a2cb93fdc64123c9ea09b5c199fd12f25ed9a8a0a82?s=96&d=mm&r=g\",\"caption\":\"afrazsanat\"},\"url\":\"https:\/\/afraz-sanat.com\/index.php\/author\/afrazsanat\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Debugging MS Outlook 2010 VB script used in a rule - Afraz-sanat Zonouz","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:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/","og_locale":"en_US","og_type":"article","og_title":"Debugging MS Outlook 2010 VB script used in a rule - Afraz-sanat Zonouz","og_description":"I wanted to run a VB script in MS-Outlook 2010, in a rule applied to every incoming messages, but I was\u00a0not sure what was the cause of the issue preventing it to run as I expected. It meant to find e-mails that\u00a0contain a desired word in its body, but in various upper\/lower letter combination, e.g. &hellip; Continue reading \"Debugging MS Outlook 2010 VB script used in a rule\"","og_url":"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/","og_site_name":"Afraz-sanat Zonouz","article_published_time":"2017-07-19T18:46:24+00:00","author":"afrazsanat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"afrazsanat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/","url":"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/","name":"Debugging MS Outlook 2010 VB script used in a rule - Afraz-sanat Zonouz","isPartOf":{"@id":"https:\/\/afraz-sanat.com\/#website"},"datePublished":"2017-07-19T18:46:24+00:00","author":{"@id":"https:\/\/afraz-sanat.com\/#\/schema\/person\/b9034d80592ca319227aafd344f9db69"},"breadcrumb":{"@id":"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/afraz-sanat.com\/index.php\/2017\/07\/19\/debugging-ms-outlook-2010-vb-script-used-in-a-rule\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/afraz-sanat.com\/"},{"@type":"ListItem","position":2,"name":"Debugging MS Outlook 2010 VB script used in a rule"}]},{"@type":"WebSite","@id":"https:\/\/afraz-sanat.com\/#website","url":"https:\/\/afraz-sanat.com\/","name":"Afraz-sanat Zonouz","description":"Office and industrial Automation","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/afraz-sanat.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/afraz-sanat.com\/#\/schema\/person\/b9034d80592ca319227aafd344f9db69","name":"afrazsanat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/afraz-sanat.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c9ffce4f6798f570d1cf6a2cb93fdc64123c9ea09b5c199fd12f25ed9a8a0a82?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c9ffce4f6798f570d1cf6a2cb93fdc64123c9ea09b5c199fd12f25ed9a8a0a82?s=96&d=mm&r=g","caption":"afrazsanat"},"url":"https:\/\/afraz-sanat.com\/index.php\/author\/afrazsanat\/"}]}},"_links":{"self":[{"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":1,"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":87,"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/posts\/55\/revisions\/87"}],"wp:attachment":[{"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afraz-sanat.com\/index.php\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}