{"id":63933,"date":"2007-09-27T02:17:00","date_gmt":"2007-09-27T02:17:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/09\/27\/how-can-i-create-a-new-folder-in-microsoft-outlook\/"},"modified":"2007-09-27T02:17:00","modified_gmt":"2007-09-27T02:17:00","slug":"how-can-i-create-a-new-folder-in-microsoft-outlook","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-create-a-new-folder-in-microsoft-outlook\/","title":{"rendered":"How Can I Create a New Folder in Microsoft Outlook?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I create a new folder in Microsoft Outlook?<BR><BR>&#8212; TY<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, TY. You know, this is an exciting time here at Microsoft; after all, last night at midnight we officially released one of the most highly-anticipated software products ever created: a script that can create a new folder in Microsoft Outlook!<\/P>\n<P>Oh, wait; sorry. We\u2019re releasing that script right now. Last night we released some video game. Halo Something-Or-Other.<\/P>\n<P>No, hey, just kidding: even people as out-of-it as the Scripting Guys know about Halo 3. After all, if you watch TV, read magazines, drink soda or do just about <I>anything<\/I> then you can\u2019t help but know about Halo 3.<\/P>\n<P>And the Scripting Guys watch a lot of TV and drink a lot of soda.<\/P>\n<P>In case you\u2019re wondering, however, the answer is: no, the Scripting Guy who writes this column did not stand in line at midnight in order to be one of the first people to receive a copy of Halo 3. To be honest, the Scripting Guy who writes this column will probably never even <I>play<\/I> Halo 3, let alone get his very own copy of it. <I>Why<\/I> won\u2019t he play Halo 3? Well, a few years ago the Scripting Guy who writes this column got talked into playing the original Halo with his then-13-year-old son and his two nephews. The boys are still laughing about that.<\/P>\n<P>How bad could that have been? Well, shortly after killing his own teammate \u2013 by accident, we hasten to add \u2013 the Scripting Guy who writes this column stumbled upon some flying vehicle, a flying vehicle armed with deadly missiles or bombs or something. \u201cOh, you are <I>so<\/I> lucky,\u201d said the Scripting Son. \u201cYou can\u2019t possibly lose now.\u201d<\/P>\n<P>And here we thought the Scripting Son knew his father better than that.<\/P>\n<TABLE class=\"dataTable\" id=\"EQD\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Note<\/B>. Does that mean that the Scripting Dad had problems flying this vehicle? No, he had trouble just getting <I>into<\/I> the vehicle. Regardless of which button or combination of buttons he pushed, he could never get onboard.<\/P>\n<P>\u201cDad, just press the X button,\u201d the Scripting Son kept saying.<\/P>\n<P>\u201cI <I>am<\/I> pressing the X button!\u201d the Scripting Dad kept replying. \u201cWait: which one is the X button?\u201d<\/P>\n<P>Fortunately one of the nephews came by and, to put it euphemistically, put the Scripting Dad out of his misery.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Besides, last night at midnight we were standing in line to get our hands on <I>this<\/I> baby: Microsoft Outlook Folder Creator 1. At the risk of making everyone out there jealous, here\u2019s what the script looks like (you can look, but don\u2019t touch):<\/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 objNewFolder = objFolder.Folders.Add(&#8220;Scripts Received&#8221;)\n<\/PRE>\n<P>Granted, this has nowhere near as many lines of code as Halo 3, and the graphics aren\u2019t quite as nice, either. But, then again, how many Microsoft Outlook folders can you create using Halo 3?<\/P>\n<P>Really? That many, huh? Wow; we never would have guessed <I>that<\/I>.<\/P>\n<TABLE class=\"dataTable\" id=\"ERE\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. Well, if nothing else our script is still <I>cheaper<\/I> than Halo 3. Although, admittedly, that\u2019s only because Microsoft won\u2019t let us charge people to read this column.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Let\u2019s see if we can figure out how Microsoft Outlook Folder Creator 1 works. We start out by defining a constant named olFolderInbox and setting the value to 6; we\u2019ll use this constant when we bind to the Inbox folder in Microsoft Outlook. After defining the constant, we create an instance of the <B>Outlook.Application<\/B> object, then use the <B>GetNamespace<\/B> method to bind to the <B>MAPI<\/B> namespace. (And yes, the MAPI namespace <I>is<\/I> the only namespace you can bind to. Nevertheless, you still have to call the GetNamespace method and make the connection.)<\/P>\n<P>From there we use this line of code to return an object reference (objFolder) to the Inbox folder:<\/P><PRE class=\"codeSample\">Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)\n<\/PRE>\n<P>Once we\u2019ve done that we can create a new folder simply by calling the <B>Add<\/B> method (part of the Inbox\u2019s <B>Folders<\/B> collection), passing the name of the new folder as the sole method parameter:<\/P><PRE class=\"codeSample\">Set objNewFolder = objFolder.Folders.Add(&#8220;Scripts Received&#8221;)\n<\/PRE>\n<P>Just like that our Inbox has a new subfolder named Scripts Received.<\/P>\n<TABLE class=\"dataTable\" id=\"EZF\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. At the risk of tooting our own horn, Halo 3 won\u2019t come right out and tell you how it ends; you have to play \u2013 and <I>win<\/I> \u2013 the game before you can find out the dramatic conclusion. The Scripting Guys would never make you do that; instead, we tell you flat out <I>exactly<\/I> how our script ends: it creates a new folder named Scripts Received.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>As we noted, our new folder is a subfolder of the Inbox. That\u2019s fine \u2026 unless you wanted this new folder to be at the same level as the Inbox (along with folders like Deleted Items, Junk Mail, and Sent Items). If that\u2019s the case, well, too bad; you\u2019re just going to have to wait until Microsoft Outlook Folder Creator 2 is released.<\/P>\n<P>Fortunately, that release date turns out to be right about now:<\/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>strFolderName = objFolder.Parent\nSet objMailbox = objNamespace.Folders(strFolderName)<\/p>\n<p>Set objNewFolder = objMailbox.Folders.Add(&#8220;Scripts Received&#8221;)\n<\/PRE>\n<P>The tricky part with this script is binding to the Outlook <I>Mailbox<\/I> as opposed to the Inbox. As far as we know, there\u2019s no straightforward way to bind to the Mailbox; we have no idea what constant value would be required to do that. But as everyone knows, all great video games have their cheat codes, and Microsoft Outlook Folder Creator is no exception. Can\u2019t bind directly to the Mailbox? That\u2019s OK; we\u2019ll just bind to the Inbox and then retrieve the value of the Inbox\u2019s <B>Parent<\/B> folder:<\/P><PRE class=\"codeSample\">strFolderName = objFolder.Parent\n<\/PRE>\n<P>Once that value has been stashed in the variable strFolderName we can then use it to create an object reference to the Mailbox folder:<\/P><PRE class=\"codeSample\">Set objMailbox = objNamespace.Folders(strFolderName)\n<\/PRE>\n<P>That\u2019s nice, but how do we create a new subfolder of the Mailbox folder? Pretty much the same way we created a new subfolder of the Inbox folder:<\/P><PRE class=\"codeSample\">Set objNewFolder = objMailbox.Folders.Add(&#8220;Scripts Received&#8221;)\n<\/PRE>\n<P>That\u2019s all there is to it.<\/P>\n<P>Now, we know what you\u2019re thinking. You\u2019re thinking, \u201cYeah, that\u2019s all well and good, but Halo 3 has a reset button. If things ever go wrong I can just press the reset button and start all over again. I bet Microsoft Outlook Folder Creator can\u2019t do <I>that<\/I>, can it?\u201d<\/P>\n<P>Oh, can\u2019t it? Take a look at this little block of code:<\/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>strFolderName = objFolder.Parent\nSet objMailbox = objNamespace.Folders(strFolderName)<\/p>\n<p>Set objNewFolder = objMailbox.Folders(&#8220;Scripts Received&#8221;)\nobjNewFolder.Delete\n<\/PRE>\n<P>You\u2019re right: this <I>does<\/I> look very similar to the script that creates a subfolder in the Mailbox folder, doesn\u2019t it? However, there are a couple of important differences. For example, after we bind to the Mailbox folder, we use this line of code to create an object reference to the Scripts Received subfolder:<\/P><PRE class=\"codeSample\">Set objNewFolder = objMailbox.Folders(&#8220;Scripts Received&#8221;)\n<\/PRE>\n<P>From there we then call the <B>Delete<\/B> method to remove the folder:<\/P><PRE class=\"codeSample\">objNewFolder.Delete\n<\/PRE>\n<P>At that point, just like Halo 3, we can start all over again.<\/P>\n<P>We hope that answers your question, TY. In the meantime, we\u2019ve got work to do: we\u2019re still negotiating with the Mountain Dew people to create a limited edition Microsoft Outlook Folder Creator-brand Mountain Dew. How are those negotiations going? To be honest, not quite as well as we had hoped. But we\u2019re working on it.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I create a new folder in Microsoft Outlook?&#8212; TY Hey, TY. You know, this is an exciting time here at Microsoft; after all, last night at midnight we officially released one of the most highly-anticipated software products ever created: a script that can create a new folder in Microsoft Outlook! [&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-63933","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 create a new folder in Microsoft Outlook?&#8212; TY Hey, TY. You know, this is an exciting time here at Microsoft; after all, last night at midnight we officially released one of the most highly-anticipated software products ever created: a script that can create a new folder in Microsoft Outlook! [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63933","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=63933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63933\/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=63933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=63933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=63933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}