{"id":53092,"date":"2023-06-25T08:06:19","date_gmt":"2023-06-25T07:06:19","guid":{"rendered":"https:\/\/ekiwi-blog.de\/53092\/vba-outlook-mark-e-mail-as-read\/"},"modified":"2023-08-19T09:46:19","modified_gmt":"2023-08-19T08:46:19","slug":"vba-outlook-mark-e-mail-as-read","status":"publish","type":"post","link":"https:\/\/ekiwi-blog.de\/en\/53092\/vba-outlook-mark-e-mail-as-read\/","title":{"rendered":"VBA Outlook: Mark e-mail as read"},"content":{"rendered":"<p>The daily email madness can sometimes be exhausting. So it&#8217;s good to be able to simplify and automate your work with a few <abbr title=\"Visual Basic for Application\">VBA<\/abbr> macros. One use case could be that you have marked one or more e-mails and want to mark them as read in one go using VBA code.<\/p>\n<p>This use case will rarely occur &#8220;<em>standalone<\/em>&#8220;. In most cases, it will be used in conjunction with other macros, e.g. if you want to mark e-mails as read and then <a title=\"Move outlook mail via VBA macro to a subfolder or archive folder\" href=\"https:\/\/ekiwi-blog.de\/en\/54082\/vba-outlook-automatically-move-e-mail-to-another-folder-with-macro\/\">automatically move them to another folder<\/a>. Or you want to reply to an e-mail <a href=\"https:\/\/ekiwi-blog.de\/en\/54162\/vba-outlook-macro-automatically-execute-on-email-receipt\/\" title=\"VBA Outlook macro automatically execute on email receipt\">automatically using a VBA macro<\/a> and then mark it as read.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of content<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ekiwi-blog.de\/en\/53092\/vba-outlook-mark-e-mail-as-read\/#Macro_mark_email_as_read\" >Macro mark email as read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ekiwi-blog.de\/en\/53092\/vba-outlook-mark-e-mail-as-read\/#Macro_mark_email_as_unread\" >Macro: mark email as unread<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ekiwi-blog.de\/en\/53092\/vba-outlook-mark-e-mail-as-read\/#Note\" >Note<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Macro_mark_email_as_read\"><\/span>Macro mark email as read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In the following image and inserted code, we can already see how small and inconspicuous the code is.<\/p>\n<figure id=\"attachment_53087\" aria-describedby=\"caption-attachment-53087\" style=\"width: 651px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-53087\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/06\/vba-outlook-macro-mark-email-as-unread.jpg\" alt=\"Screenshot of the VBA editor with the macro that marks the email as read\" width=\"651\" height=\"260\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/06\/vba-outlook-macro-mark-email-as-unread.jpg 651w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/06\/vba-outlook-macro-mark-email-as-unread-300x120.jpg 300w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><figcaption id=\"caption-attachment-53087\" class=\"wp-caption-text\">VBA code to mark e-mail as read<\/figcaption><\/figure>\n<pre><code><span style=\"color: #0000ff;\">Option Explicit<\/span>.\r\n<span style=\"color: #008000;\">'mark selected messages as read<\/span>.\r\n<span style=\"color: #0000ff;\">Sub<\/span> MarkMsgAsRead()\r\n    <span style=\"color: #0000ff;\">Dim<\/span> olItem <span style=\"color: #0000ff;\">As<\/span> Outlook.MailItem\r\n    \r\n    <span style=\"color: #0000ff;\">For Each<\/span> olItem <span style=\"color: #0000ff;\">In<\/span> Application.ActiveExplorer.Selection\r\n        <mark>olItem.UnRead = <span style=\"color: #0000ff;\">False<\/span><\/mark>\r\n    <span style=\"color: #0000ff;\">Next<\/span> olItem\r\n    \r\n<span style=\"color: #0000ff;\">End Sub<\/span><\/code><\/pre>\n<p>So there is a method <em>MarkMsgAsRead<\/em> which can then be executed from Outlook as a macro. Within the method, an <em>olItem<\/em> (short for <em>outlookItem<\/em>) is defined as an <em>MailItem<\/em>. In a <em>For-Each<\/em> loop, all emails selected in the inbox are then run through. In order to mark the MailItem as read, the <strong>property &#8220;UnRead&#8221; must be assigned the value &#8220;False&#8221;.<\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Macro_mark_email_as_unread\"><\/span>Macro: mark email as unread<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Of course, the whole thing also works in reverse, so that you can mark e-mails that have already been marked as read as unread. To do this, simply set the <strong>&#8220;UnRead&#8221; property to &#8220;True&#8221;<\/strong>.<\/p>\n<pre><code><span style=\"color: #0000ff;\">Option Explicit<\/span>\r\n<span style=\"color: #008000;\"><span style=\"colour: #008000;\">'mark selected messages as unread<\/span>.<\/span>\r\n<span style=\"color: #0000ff;\">Sub<\/span> MarkMsgAsUnRead()\r\n    <span style=\"color: #0000ff;\">Dim<\/span> olItem <span style=\"color: #0000ff;\">As<\/span> Outlook.MailItem\r\n    \r\n    <span style=\"color: #0000ff;\">For Each<\/span> olItem <span style=\"color: #0000ff;\">In<\/span> Application.ActiveExplorer.Selection\r\n        <mark>olItem.UnRead = <span style=\"color: #0000ff;\">True<\/span><\/mark>\r\n    <span style=\"color: #0000ff;\">Next<\/span> olItem\r\n    \r\n<span style=\"color: #0000ff;\">End Sub<\/span><\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Note\"><\/span>Note<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A final note: If you get error messages the first time you run the code, just check that you have selected the correct references\/libraries. These can be found in the menu under <strong>Tools \u2794 References<\/strong>.<\/p>\n<figure id=\"attachment_53075\" aria-describedby=\"caption-attachment-53075\" style=\"width: 445px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-53075\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/06\/vba-editor-necessary-references-for-outlook.jpg\" alt=\"Screenshot of the necessary references in the VBA editor\" width=\"445\" height=\"364\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/06\/vba-editor-necessary-references-for-outlook.jpg 445w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2023\/06\/vba-editor-necessary-references-for-outlook-300x245.jpg 300w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><figcaption id=\"caption-attachment-53075\" class=\"wp-caption-text\">Screenshot of the necessary references in the VBA editor<\/figcaption><\/figure>","protected":false},"excerpt":{"rendered":"<p>The daily email madness can sometimes be exhausting. So it&#8217;s good to be able to simplify and automate your work<\/p>\n","protected":false},"author":2,"featured_media":13630,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1555],"tags":[3156,3155,2252,1707,2737,3153,3154,1857,1858,2168,1569,1859,1860,1861,2715,1862,2068],"class_list":["post-53092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-en","tag-automatisch-en","tag-automatisieren-en","tag-code-en","tag-macro","tag-macros","tag-makro-en","tag-makros-en","tag-microsoft-en-2","tag-microsoft-office-en-2","tag-office-en","tag-outlook-en","tag-programmieren-en","tag-programmierung-en","tag-vba-en-2","tag-vba-code-en","tag-visual-basic-for-application-en-2","tag-windows-en-2"],"_links":{"self":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/53092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/comments?post=53092"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/53092\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media\/13630"}],"wp:attachment":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media?parent=53092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/categories?post=53092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/tags?post=53092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}