{"id":65333,"date":"2007-03-13T01:39:00","date_gmt":"2007-03-13T01:39:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/03\/13\/how-can-i-determine-the-follow-up-status-of-outlook-emails\/"},"modified":"2007-03-13T01:39:00","modified_gmt":"2007-03-13T01:39:00","slug":"how-can-i-determine-the-follow-up-status-of-outlook-emails","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-the-follow-up-status-of-outlook-emails\/","title":{"rendered":"How Can I Determine the Follow-Up Status of Outlook Emails?"},"content":{"rendered":"<p><H2><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> <\/H2>\n<P>Hey, Scripting Guy! How can I go through all the emails in an Outlook folder and determine which messages are flagged for follow-up and which messages <I>were<\/I> flagged for follow-up but are now complete?<BR><BR>&#8212; KF<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, KF. We\u2019ll be honest with you: we\u2019re going to <I>try<\/I> to get to your question today, but first we\u2019ve got something far more important to do. Yesterday when he got home the Scripting Guy who writes this column found a letter in his mailbox from the Cambridge Who\u2019s Who. This letter informed him that he was \u201cbeing considered for inclusion in the 2007\/2008 Cambridge Who\u2019s Who Among Executives and Professionals \u2018Honors Edition\u2019 of the Registry.\u201d<\/P>\n<P>Was the Scripting Guy who writes this column excited by this? That\u2019s putting it mildly; as the letter notes \u201cInclusion is considered by many as the single highest mark of achievement.\u201d You can count the Scripting Guy who writes this column as being one of those people who consider this their single highest mark of achievement. And no, that isn\u2019t because he doesn\u2019t actually <I>have<\/I> any other achievements. He doesn\u2019t, but that\u2019s not why he\u2019s so excited.<\/P>\n<P>Hold on a second here. You know, now that we look at this a little more closely we realize that there\u2019s a string attached: to actually be included in the Registry itself you need to fill out an application form, indicating such things as the company you work for, your job title, and your specialty. Uh-oh; apparently you don\u2019t get this honor unless you\u2019ve actually done something to deserve it. Is that a problem? You bet it is. After all, we were hoping this was like the Nobel Prize for Literature which, as near as we can tell, is awarded simply by drawing names out of a hat.<\/P>\n<P>So what exactly <I>is<\/I> the Scripting Guy who writes this column\u2019s specialty? To tell you the truth, we were hoping <I>you\u2019d<\/I> tell <I>us<\/I>. But let\u2019s see, he can \u2026 um \u2026 he\u2019s good at \u2026 he \u2026. Oh, wait we know: he can write scripts that can go through all the emails in an Outlook folder and determine which messages are flagged for follow-up and which messages <I>were<\/I> flagged for follow-up but are now complete:<\/P><PRE class=\"codeSample\">Const olFolderInbox = 6<\/p>\n<p>Set objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)\nSet objFolder = objNamespace.GetDefaultFolder(olFolderInbox)<\/p>\n<p>Set colItems = objFolder.Items<\/p>\n<p>For Each objItem in colItems\n    If objItem.FlagStatus = 1 Then\n        Wscript.Echo &#8220;Follow-up complete&#8221;\n        Wscript.Echo objItem.Subject \n        Wscript.Echo\n    End If<\/p>\n<p>    If objItem.FlagStatus = 2 Then\n        Wscript.Echo &#8220;Marked for follow-up&#8221;\n        Wscript.Echo objItem.Subject \n        Wscript.Echo\n    End If\nNext\n<\/PRE>\n<P>What\u2019s that? You\u2019d like to know how this script actually works? Well, explaining things isn\u2019t exactly our specialty, but we\u2019ll see what we can do.<\/P>\n<P>We start out by defining a constant named olFolderInbox and setting the value to 6; that\u2019s going to tell our script which folder we want to work with. And that folder is \u2013 oh, that\u2019s right: the Inbox folder. Apparently the constant name was a bit of a giveaway, wasn\u2019t it?<\/P>\n<P>Oh, well; so much for the suspense, huh? (Fortunately writing stuff that has no suspense and no plot will actually <I>help<\/I> our chances of getting the Nobel Prize for Literature.) After defining the constant olFolderInbox we then use these three lines of code to create an instance of the <B>Outlook.Application<\/B> object, connect to the <B>MAPI<\/B> namespace, and bind to the Inbox folder:<\/P><PRE class=\"codeSample\">Set objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)\nSet objFolder = objNamespace.GetDefaultFolder(olFolderInbox)\n<\/PRE>\n<P>Once we\u2019ve done that we then use this line of code to return a collection of all the mail messages found in that folder:<\/P><PRE class=\"codeSample\">Set colItems = objFolder.Items\n<\/PRE>\n<P>At this point there are at least two different paths we can take: we can write a filter to weed out messages that don\u2019t have <I>any<\/I> follow-up flag setting, or we can simply loop through the entire collection and check the flag setting for each and every item. Because people tend to find Outlook filters confusing we\u2019ve opted to loop through the entire collection. But if you\u2019re willing to tackle filter writing you\u2019ll find some information about that very thing in this <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/officetips\/aug05\/tips0818.mspx\"><B>Office Space article<\/B><\/A>.<\/P>\n<P>And no, we can\u2019t guarantee that writing an Outlook filter script will get you included in the Registry alongside the Scripting Guy who writes this column. But it can\u2019t hurt.<\/P>\n<P>Seeing as how we\u2019ve decided to loop through the entire collection our next step is to set up a For Each loop that, well, loops through the entire collection. The first thing we see inside that loop is a block of code that looks like this:<\/P><PRE class=\"codeSample\">If objItem.FlagStatus = 1 Then\n    Wscript.Echo &#8220;Follow-up complete&#8221;\n    Wscript.Echo objItem.Subject \n    Wscript.Echo\nEnd If\n<\/PRE>\n<P>What we\u2019re doing here is examining the value of the <B>FlagStatus<\/B> property. If FlagStatus is equal to 1 that means that this particular email was originally marked for follow-up but the follow-up is now complete. (In Outlook itself you\u2019ll see a little checkmark in the status column.) Therefore, we echo back the fact that follow-up is complete; in addition, we echo back the email Subject line (just so we can tell <I>which<\/I> message has been marked as follow-up complete).<\/P>\n<P>Good question: what about emails that are <I>still<\/I> marked for follow-up? Well, that\u2019s what this block of code is for:<\/P><PRE class=\"codeSample\">If objItem.FlagStatus = 2 Then\n    Wscript.Echo &#8220;Marked for follow-up&#8221;\n    Wscript.Echo objItem.Subject \n    Wscript.Echo\nEnd If\n<\/PRE>\n<P>Here we\u2019re checking to see if the value of FlagStatus is equal to 2; it probably goes without saying that this represents an email still marked for follow-up. In a case like that we then echo back the appropriate message (<I>Marked for follow-up<\/I>) as well as the subject line.<\/P>\n<P>And then, of course, we loop around and repeat the process with the next message in the Inbox. What if we encounter an email that has no follow-up status of any kind (neither complete nor pending)? That\u2019s easy. That means that the FlagStatus for the message is equal to 0, which in turn means that we simply skip that particular email.<\/P>\n<P>Incidentally, there are a couple of other follow-up related properties you might be interested in. For example, if you\u2019d like to know the actual color of the flag assigned to a message use the <B>FlagIcon<\/B> property and one of these values:<\/P>\n<TABLE id=\"EOF\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Constant<\/B><\/P><\/TD>\n<TD>\n<P class=\"lastInCell\"><B>Value<\/B><\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olBlueFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">5<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olGreenFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">3<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olNoFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">0<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olOrangeFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">2<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olPurpleFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">1<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olRedFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">6<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">olYellowFlagIcon<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">4<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>And if you\u2019d like to know <I>when<\/I> you\u2019re supposed to follow-up a message you can look at the value of the <B>FlagDueBy<\/B> property. (If no due date has been assigned then this property defaults to 1\/1\/4501, which probably <I>still<\/I> isn\u2019t enough time for the Scripting Guy who writes this column to follow-up on all the items he has marked for follow-up.) As an added bonus, all these properties are read\/write, which means you can programmatically change the follow-up status, icon, or due date. Pretty cool, huh?<\/P>\n<P>OK; so much for that. We\u2019re willing to bet that some of you are skeptical about this whole Who\u2019s Who thing. \u201cIs the Scripting Guy who writes that column <I>really<\/I> among the \u2018country\u2019s most accomplish professionals,\u2019\u201d you\u2019re wondering, \u201cor is his name simply on some mailing list somewhere?\u201d To tell you the truth, we\u2019re not worried about that. After all, when you\u2019ve earned as many honors and awards as the Scripting Guy who writes this column (0, unless you count making the Little League and PONY League All-Star teams), well \u2026.<\/P>\n<P>Hey, wait a second: why <I>don\u2019t<\/I> you count making the Little League and PONY League All-Star teams? That\u2019s <I>way<\/I> more than Bill Gates ever did. <\/P>\n<P>Well, baseball-wise, anyway.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I go through all the emails in an Outlook folder and determine which messages are flagged for follow-up and which messages were flagged for follow-up but are now complete?&#8212; KF Hey, KF. We\u2019ll be honest with you: we\u2019re going to try to get to your question today, but first we\u2019ve [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[212,49,3,5],"class_list":["post-65333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-outlook","tag-office","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I go through all the emails in an Outlook folder and determine which messages are flagged for follow-up and which messages were flagged for follow-up but are now complete?&#8212; KF Hey, KF. We\u2019ll be honest with you: we\u2019re going to try to get to your question today, but first we\u2019ve [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=65333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=65333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=65333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=65333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}