{"id":64913,"date":"2007-05-08T22:05:00","date_gmt":"2007-05-08T22:05:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/05\/08\/how-can-i-list-all-the-meetings-scheduled-by-a-specified-person\/"},"modified":"2007-05-08T22:05:00","modified_gmt":"2007-05-08T22:05:00","slug":"how-can-i-list-all-the-meetings-scheduled-by-a-specified-person","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-list-all-the-meetings-scheduled-by-a-specified-person\/","title":{"rendered":"How Can I List All the Meetings Scheduled By a Specified Person?"},"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 get a list of all the upcoming meetings that have been scheduled by a specific person (namely, my manager)?<BR><BR>&#8212; GH<\/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, GH. Before we tackle this question we\u2019d like to reassure anyone who looked out their window recently and saw pigs flying; that\u2019s to be expected. Likewise, any of our readers who happen to be residents of Hades might have been alarmed by the recent cold snap down there. Trust us; there\u2019s nothing to be alarmed about. Pigs flying, hell freezing over \u2013 those things are bound to happen when the Scripting Son draws a walk in his last at-bat of the high school baseball season. <\/P>\n<P>That\u2019s right, after 18 games and 60-some at-bats the Scripting Son finally drew a walk, and in his last at-bat of the season to boot. Not that this is particularly unusual. Three years ago, for example, he was on an all-star team that toured Japan. During that time he played in 14 games and walked once: in his final at-bat. That same year he went the entire regular season (nearly 40 games) without walking at all; oddly enough, in his first playoff game, he then walked three times. Last year the Scripting Son played in 60 games and walked four times. Etc., etc.<\/P>\n<P>Needless to say, the Scripting Son doesn\u2019t like to walk.<\/P>\n<P>So what difference does this make to you, GH? Quite a bit, believe it or not. After all, the Scripting Guy who writes this column has always said, \u201cWrite a script that retrieves a list of upcoming appointments that have been scheduled by a specific person? When pigs fly!\u201d<\/P>\n<P>Well, in that case:<\/P><PRE class=\"codeSample\">Const olFolderCalendar = 9<\/p>\n<p>Set objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)\nSet objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)<\/p>\n<p>Set colItems = objFolder.Items<\/p>\n<p>strFilter = &#8220;[Organizer] = &#8216;Ken Myer'&#8221;\nSet colFilteredItems = colItems.Restrict(strFilter)<\/p>\n<p>For Each objItem In colFilteredItems\n    If objItem.Start &gt; Now Then\n        Wscript.Echo &#8220;Meeting name: &#8221; &amp; objItem.Subject\n        Wscript.Echo &#8220;Meeting date: &#8221; &amp; objItem.Start\n        Wscript.Echo &#8220;Duration: &#8221; &amp; objItem.Duration &amp; &#8221; minutes&#8221;\n        Wscript.Echo &#8220;Location: &#8221; &amp; objItem.Location\n        Wscript.Echo\n    End If\nNext\n<\/PRE>\n<P>Before we explain how this works we need to go turn up the heat; for some reason it seems a little colder here than it usually is. <\/P>\n<P>OK, that\u2019s better. As you can see, we start out by defining a constant named olFolderCalendar and setting the value to 9; we\u2019ll use this constant to tell Outlook which folder (the Calendar folder) we want to work with. Next we create an instance of the <B>Outlook.Application<\/B> object, then connect to the <I>MAPI<\/I> namespace (which happens to be the <I>only<\/I> namespace we can connect to). We then use the <B>GetDefaultFolder<\/B> method to bind to the Calendar folder in Outlook:<\/P><PRE class=\"codeSample\">Set objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)\n<\/PRE>\n<P>That <I>was<\/I> pretty easy, wasn\u2019t it?<\/P>\n<P>Our next step is to create an object reference to the folder\u2019s <B>Items<\/B> property:<\/P><PRE class=\"codeSample\">Set colItems = objFolder.Items\n<\/PRE>\n<P>What does that do for us? That grabs a collection of all our appointments (that is, everything in the Calendar folder) and stashes it in a variable named colItems. <\/P>\n<P>And yes, you\u2019re right: we\u2019re <I>not<\/I> interested in all the items in the Calendar folder, are we? Instead, we\u2019re only interested in upcoming meetings that have been organized by our manager, Ken Myer. Somehow we need to filter our collection. But how?<\/P>\n<P>Well, here\u2019s one suggestion: why not apply a filter?<\/P><PRE class=\"codeSample\">strFilter = &#8220;[Organizer] = &#8216;Ken Myer'&#8221;\nSet colFilteredItems = colItems.Restrict(strFilter)\n<\/PRE>\n<P>As you can see, in the first line of code we assign a filter value to the variable strFilter. Filters are made up of two parts: a property name (enclosed in square brackets) and a property value (in this case, a value enclosed in single quote marks, because we are dealing with a string). We want to limit our data to meetings arranged by Ken Myer; that is, meetings where the <B>Organizer<\/B> property is equal to <I>Ken Myer<\/I>. Hence the two parts of our filter: <B>[Organizer]<\/B> and <B>\u2018Ken Myer\u2019<\/B>.<\/P>\n<P>In line 2, we then call the <B>Restrict <\/B>method to apply this filter to our collection. That\u2019s going to create a new collection (named colFilteredItems) that contains information only about those meetings organized by Ken Myer.<\/P>\n<P>That\u2019s <I>almost<\/I> what we need. However, this sub-collection will contain all the meetings organized by Ken Myer, including those that have already taken place. Because GH is only interested in upcoming meetings, we need to weed out the meetings that have already taken place. <\/P>\n<P>In theory, we could do that by making a fancier filter. However, filtering on dates can be a bit complicated; therefore, we decided to take the easy way out. Rather than apply a double filter \u2013 one that limits returned data to meetings organized by Ken Myer, provided that those meetings haven\u2019t been held yet \u2013 we applied a filter that returns all the meetings organized by Ken Myer. We then set up a For Each loop to walk through the complete collection of meetings. And what\u2019s the first thing we do in that loop? Check to see if the meeting has already been held:<\/P><PRE class=\"codeSample\">If objItem.Start &gt; Now Then\n<\/PRE>\n<P>If the meeting\u2019s <B>Start<\/B> time is later than the current date and time (which we can determine using VBScript\u2019s <B>Now<\/B> function) that means that the meeting hasn\u2019t taken place yet. Therefore, we go ahead and echo back the meeting\u2019s name, start time, duration, and location; that\u2019s what this block of code is for:<\/P><PRE class=\"codeSample\">Wscript.Echo &#8220;Meeting name: &#8221; &amp; objItem.Subject\nWscript.Echo &#8220;Meeting date: &#8221; &amp; objItem.Start\nWscript.Echo &#8220;Duration: &#8221; &amp; objItem.Duration &amp; &#8221; minutes&#8221;\nWscript.Echo &#8220;Location: &#8221; &amp; objItem.Location\n<\/PRE>\n<P>And then we loop around and repeat the process with the next meeting in the collection. <\/P>\n<P>One thing to watch out for here. Because of the way Outlook stores recurring appointments, those appointments might not show up in your output. That\u2019s due, in large part, to the fact that the start date for a recurring appointment might be long-since past. Because of that, you might need to use <I>two<\/I> scripts to make sure you get the desired information: the script we just showed you, and a second script designed to retrieve the recurring appointments organized by Ken Myer. What might that second script look like? It might look a little like this:<\/P><PRE class=\"codeSample\">Const olFolderCalendar = 9<\/p>\n<p>Set objOutlook = CreateObject(&#8220;Outlook.Application&#8221;)\nSet objNamespace = objOutlook.GetNamespace(&#8220;MAPI&#8221;)\nSet objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)<\/p>\n<p>Set colItems = objFolder.Items<\/p>\n<p>strFilter = &#8220;[IsRecurring] = TRUE AND [Organizer] = &#8216;Ken Myer'&#8221;<\/p>\n<p>Set colFilteredItems = colItems.Restrict(strFilter)<\/p>\n<p>For Each objItem In colFilteredItems\n    Set objPattern = objItem.GetRecurrencePattern\n    If objPattern.PatternEndDate &gt; Now Then\n        Wscript.Echo &#8220;Meeting name: &#8221; &amp; objItem.Subject\n        Wscript.Echo &#8220;Duration: &#8221; &amp; objItem.Duration &amp; &#8221; minutes&#8221;\n        Wscript.Echo &#8220;Location: &#8221; &amp; objItem.Location\n        Wscript.Echo &#8220;Recurrence type: &#8221; &amp; objPattern.RecurrenceType\n        Wscript.Echo &#8220;Start time: &#8221; &amp; objPattern.StartTime\n        Wscript.Echo &#8220;Start date: &#8221; &amp; objPattern.PatternStartDate\n        Wscript.Echo &#8220;End date: &#8221; &amp; objPattern.PatternEndDate\n        Wscript.Echo\n    End If\nNext\n<\/PRE>\n<P>Of course, you could always combine the two scripts into a single script. But we\u2019ll let you take care of that yourself.<\/P>\n<TABLE class=\"dataTable\" id=\"EOF\" 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>. You say you don\u2019t understand how the preceding script works? Then you might want to take a look at our <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/officetips\/sept05\/tips0901.mspx\"><B>Office Space article<\/B><\/A> on retrieving recurring appointments.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Meanwhile, the Scripting Son is getting ready for his summer ball season, a season in which he\u2019ll play another 50-to-60 games. Will he draw many walks during <I>this<\/I> season? Probably not; at least when it comes to baseball the Scripting Son is impatient, he\u2019s impetuous, and he just goes out there and acts without thinking.<\/P>\n<P>Wonder where he learned all that from \u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I get a list of all the upcoming meetings that have been scheduled by a specific person (namely, my manager)?&#8212; GH Hey, GH. Before we tackle this question we\u2019d like to reassure anyone who looked out their window recently and saw pigs flying; that\u2019s to be expected. Likewise, any of [&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-64913","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 get a list of all the upcoming meetings that have been scheduled by a specific person (namely, my manager)?&#8212; GH Hey, GH. Before we tackle this question we\u2019d like to reassure anyone who looked out their window recently and saw pigs flying; that\u2019s to be expected. Likewise, any of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64913","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=64913"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/64913\/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=64913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=64913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=64913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}