{"id":55723,"date":"2008-04-23T01:13:00","date_gmt":"2008-04-23T01:13:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2008\/04\/23\/hey-scripting-guy-how-can-i-schedule-a-meeting-each-monday-through-friday-for-two-weeks\/"},"modified":"2008-04-23T01:13:00","modified_gmt":"2008-04-23T01:13:00","slug":"hey-scripting-guy-how-can-i-schedule-a-meeting-each-monday-through-friday-for-two-weeks","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-schedule-a-meeting-each-monday-through-friday-for-two-weeks\/","title":{"rendered":"Hey, Scripting Guy! How Can I Schedule a Meeting Each Monday Through Friday For Two Weeks?"},"content":{"rendered":"<p><img decoding=\"async\" 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\" \/> <\/p>\n<p>Hey, Scripting Guy! How can I schedule a meeting to occur every day, Monday through Friday, for two weeks?<br \/>&#8212; GB<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\" \/><img decoding=\"async\" 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 decoding=\"async\" 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> <\/p>\n<p>Hey, GB. As it turns out, the Scripting Guy who writes this column has <i>not<\/i> moved to some place where it doesn\u2019t <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/apr08\/hey0421.mspx\"><b>snow in April<\/b><\/a>. That\u2019s not because the Seattle area didn\u2019t get the predicted snow this past weekend; on the contrary, it <i>did <\/i>snow, and not only on Friday April 18<sup>th<\/sup>, but on each of the next to days as well. The Scripting Guy who writes this column had threatened to quit his job and move if it snowed in late April in Seattle, but cooler heads \u2013 including those at the mortgage company, the University of Idaho, and the place where he got his car loam \u2013 talked him out of it. <\/p>\n<p>But if it snows in May, well \u2026.<\/p>\n<p>So how bad could the weather have been this past weekend? Well, there\u2019s an old joke in the Seattle area that goes something like this: if you don\u2019t like the weather, just wait 15 minutes. That was definitely the case this past weekend. Sunshine? Believe it or not, at times we actually did have sunshine, and blindingly-bright sunshine at that. Snow? On Friday there was enough snow to cover the ground, and to make you brush off your car windows before you could drive anywhere. Rain? OK, that\u2019s a silly question; after all, this <i>is<\/i> Seattle we\u2019re talking about. Hail? You bet we had hail; in fact, we hail the size of \u2026 well, hailstones. Wind? We had so much wind that \u2013 you know, now that we think about it, we don\u2019t remember much wind over the weekend. But just wait a second and that\u2019s bound to change \u2026 ah, there\u2019s your wind now, right on schedule.<\/p>\n<table id=\"EQD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. In case you\u2019re wondering, at 2:09 PM Seattle time the temperature is 43 degrees Fahrenheit, with a wind chill factor of 38 degrees. The forecast for the rest of the day? \u201cRain showers this evening with mostly cloudy conditions overnight. Low 34F. Winds E at 5 to 10 mph.\u201d<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>Regardless, it was an absolutely miserable weekend, one of the worst the Scripting Guy who writes this column has ever been forced to endure. (And yes, that includes the weekend he spent at a bed-and-breakfast, where one morning he sat next to a couple from Chicago who said, \u201cWe had the best day yesterday. We drove out a little ways out of town and found this majestic old evergreen tree and we just sat down and stared at the tree for the rest of the day.\u201d) Of course, as the Scripting Editor noted, \u201cIf this was January you wouldn\u2019t think the weather was <i>that<\/i> bad.\u201d In other words, we should be happy that we\u2019re getting a so-so day in January in late April. Thanks, Scripting Editor; we feel <i>much<\/i> better now!<\/p>\n<p>As you all know, it\u2019s extremely rare for the Scripting Guy who writes this column to complain about anything; that\u2019s just not his nature. On those rare occasions when he <i>does<\/i> complain, however, he usually concludes his rant by saying, \u201cOn the bright side, the fact that <i>X<\/i> occurred <i>did<\/i> give us plenty of time to write a script that answered today\u2019s question.\u201d However, he\u2019s not going to say that today; when you have snow and a high temperature of 45 degrees in late April there <i>is<\/i> no bright side. Nevertheless, after a little trial-and-error he was still able to write a script that can schedule a meeting each workday (Monday through Friday) for a two-week period:<\/p>\n<pre class=\"codeSample\">Const olAppointmentItem = 1\nConst olMeeting = 1\nConst OlRequired = 1\nConst olRecursWeekly = 1\n\nSet objOutlook = CreateObject(\"Outlook.Application\")\nSet objAppointment = objOutlook.CreateItem(olAppointmentItem)\n\nobjAppointment.Start = #5\/5\/2008 11:00 AM#\nobjAppointment.Duration = 60\nobjAppointment.MeetingStatus = olMeeting\nobjAppointment.Subject = \"Scripting Guys meeting\"\nobjAppointment.Body = \"Meeting with Scripting Guys to discuss upcoming plans.\"\nobjAppointment.Location = \"42\/2039\"\nobjAppointment.ReminderMinutesBeforeStart = 15\nobjAppointment.ReminderSet = True\n\nSet objRecurrence = objAppointment.GetRecurrencePattern\nobjRecurrence.RecurrenceType = olRecursWeekly\nobjRecurrence.DayOfWeekMask = 2 OR 4 OR 8 OR 16 OR 32\nobjRecurrence.PatternStartDate = #5\/5\/2008#\nobjRecurrence.Occurrences = 10\n \nSet colRecipients = objAppointment.Recipients\nSet objRecipient = colRecipients.Add(\"kenmyer\")\nobjRecipient.Type = olRequired\nobjAppointment.Send\n<\/pre>\n<p>As you can see \u2013 and unlike the weather in the Seattle area \u2013 we start out in reasonable fashion, defining a constant named olAppointmentItem and another constant named olMeeting; these two constants tell the script that we want to create an instance of Outlook\u2019s <b>AppointmentItem<\/b> class and that we want this instance to be a meeting (as opposed to a plain old appointment). We then define a third constant (olRequired) which tells the script that the attendee we\u2019re planning to invite to the meeting is a required attended.<\/p>\n<p>We then create one final constant, olRecursWeekly. This is the part that threw us off at first. Because we want to create a series of meetings that convene every weekday for 2 weeks we assumed that we needed to create a daily meeting. That made sense to us, but it made no sense whatsoever to Outlook; Outlook promptly rejected our meeting request with the terse comment, \u201cThe property for the recurrence type is not valid. Verify your code.\u201d Of course, verifying our code (whatever that means) didn\u2019t do us much good, either; it was only when we <i>changed<\/i> our code (by changing the recurrence type to a weekly meeting) that the script worked.<\/p>\n<table id=\"E3E\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. If we\u2019d played with this a little bit more we might have figured out what Outlook was doing; at that point the recurrence type \u2013 that is, when to set something as a daily meeting and when to set something as a weekly meeting \u2013 might have made more sense to us. But the Scripting Son is supposed to have a baseball game this afternoon (a game that was snowed out Friday evening, then snowed out again Saturday afternoon) and, well, priorities <i>are<\/i> priorities, right?<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After defining our constants, we next create an instance of the <b>Outlook.Application<\/b> object, then use the following line of code (and the <b>CreateItem<\/b> method) to create a new AppointmentItem object:<\/p>\n<pre class=\"codeSample\">Set objOutlook = CreateObject(\"Outlook.Application\")\nSet objAppointment = objOutlook.CreateItem(olAppointmentItem)\n<\/pre>\n<p>At this point we have a big block of code where we configure various properties of our appointment item, including such things as the meeting <b>Duration<\/b> (60 minutes) and the fact that this <i>is<\/i> a meeting rather than an appointment. (Something we do by set the <b>MeetingStatus<\/b> property to the constant olMeeting.) We won\u2019t discuss these properties in any detail today, in part because most of them are self-explanatory, and in part because we have an <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/officetips\/apr05\/tips0405.mspx\"><b>Office Space article<\/b><\/a> that explains what they are and how they should be used.<\/p>\n<p>Instead, we\u2019re going to turn our attention to the following block of code:<\/p>\n<pre class=\"codeSample\">Set objRecurrence = objAppointment.GetRecurrencePattern\nobjRecurrence.RecurrenceType = olRecursWeekly\nobjRecurrence.DayOfWeekMask = 2 OR 4 OR 8 OR 16 OR 32\nobjRecurrence.PatternStartDate = #5\/5\/2008#\nobjRecurrence.Occurrences = 10\n<\/pre>\n<p>This is the portion of the script where we define our recurrence pattern; that is, this is where we determine the actual days that our meeting will take place. In order to do that, we first use the <b>GetRecurrencePattern<\/b> method to retrieve the recurrence pattern object that corresponds to our appointment item:<\/p>\n<p>Set objRecurrence = objAppointment.GetRecurrencePattern<\/p>\n<p>Once we\u2019ve latched onto the recurrence pattern object the first thing we do is set the <b>RecurrenceType<\/b> to weekly (using the constant olRecursWeekly). That brings us to this line of code:<\/p>\n<pre class=\"codeSample\">objRecurrence.DayOfWeekMask = 2 OR 4 OR 8 OR 16 OR 32\n<\/pre>\n<p>What we\u2019re doing here is defining the days of the week that the meeting will take place. The <b>DayOfWeekMask<\/b> property is a \u201cbitmask\u201d property, a bitmask being a single property that can hold multiple values (provided those value are assigned using Boolean logic). Outlook uses the following values to represent the individual days of the week:<\/p>\n<table id=\"EXG\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Day<\/b><\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\"><b>Value<\/b><\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Sunday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">1<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Monday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">2<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Tuesday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">4<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Wednesday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">8<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Thursday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">16<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Friday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">32<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\">Saturday<\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">64<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p><b>In our script, we\u2019re assigning the days Monday (2) through Friday (32) as meeting days. Admittedly, it might not <\/b><i>look<\/i> like we\u2019re assigning all five days as meeting days; that\u2019s because, in Boolean logic, the OR operator functions more like the word \u201cand.\u201d Our code looks like this:<\/p>\n<pre class=\"codeSample\">2 OR 4 OR 8 OR 16 OR 32\n<\/pre>\n<p>However, it <i>reads<\/i> like this:<\/p>\n<pre class=\"codeSample\">2 and 4 and 8 and 16 and 32\n<\/pre>\n<p>Or, substituting the day names for the values:<\/p>\n<pre class=\"codeSample\">Monday and Tuesday and Wednesday and Thursday and Friday\n<\/pre>\n<p>Quick quiz: what if we only wanted to meet on Tuesdays and Thursdays? That\u2019s right; in that case we\u2019d assign the values 4 (Tuesday) and 16 (Thursday) to the DayOfWeekMask:<\/p>\n<pre class=\"codeSample\">4 OR 16\n<\/pre>\n<p>By the way, good answer.<\/p>\n<p>We next set the <b>PatternStartDate<\/b> property to May 5, 2008 (the day of the first meeting). That makes sense; to be honest, the next line of code makes about as much sense as snow in April:<\/p>\n<pre class=\"codeSample\">objRecurrence.Occurrences = 10\n<\/pre>\n<p>As you just saw, we set the PatternStartDate property to indicate the day of the first meeting in the series. Logically enough, we initially assumed that we\u2019d then set the PatternEndDate property to the day of the <i>last<\/i> meeting in the series. When we did so, however, we got some <i>really<\/i> strange results, none of which featured a series of 10 meetings, Monday through Friday, running from May 5<sup>th<\/sup> through May 16<sup>th<\/sup>. No matter what we tried we got nothing but gobbledygook when we assigned a value to the PatternEndDate property. When we set the <b>Occurrences<\/b> property to 10, however (indicating that we wanted to hold 10 separate meetings) then everything worked just fine.<\/p>\n<p>The moral of the story? To tell you the truth, we have no idea what the moral of the story is. We just know that setting the Occurrences property gave us the meeting assignments we desired.<\/p>\n<p>All that\u2019s left at this point is to send the meeting request to the desired attendees. For example, this block of code sends a meeting invitation to kenmyer:<\/p>\n<pre class=\"codeSample\">Set colRecipients = objAppointment.Recipients\nSet objRecipient = colRecipients.Add(\"kenmyer\")\nobjRecipient.Type = olRequired\nobjAppointment.Send\n<\/pre>\n<p>In line 1 we\u2019re creating an instance of the <b>Recipients<\/b> collection; that should be fairly obvious. In lines 2 and 3 we use the <b>Add<\/b> method to add kenmyer to the collection, and to configure his attendance status as required (using the constant olRequired), respectively. Finally, in line 4 we use the <b>Send<\/b> method to send the meeting request to our lone attendee.<\/p>\n<p>What\u2019s that? Can we invite more than one person to a meeting? Of course we can; all we have to do is add that person to the Recipients collection, and configure their attendance type. For example, this block of code invites both kenmeyer and pilarackerman to a meeting:<\/p>\n<pre class=\"codeSample\">Set colRecipients = objAppointment.Recipients\n\nSet objRecipient = colRecipients.Add(\"kenmyer\")\nobjRecipient.Type = olRequired\nSet objRecipient = colRecipients.Add(\"pilarackerman\")\nobjRecipient.Type = olRequired\n\nobjAppointment.Send\n<\/pre>\n<p>And so on.<\/p>\n<p>That should do it, GB; please let us know if it <i>doesn\u2019t<\/i> do it. As for the Seattle area, the Scripting Guy who writes this column happened to stumble upon the following paragraph in an article on <a href=\"http:\/\/www.frommers.com\/destinations\/seattle\/0032010002.html\" target=\"_blank\"><b>Frommers.com<\/b><\/a>:<\/p>\n<p>\u201cSeattle&#8217;s rainy weather may be infamous, but Seattleites have ways of dealing with the dreary days. They either put on their rain gear and head outdoors just as if the sun were shining, or they retreat to the city&#8217;s hundreds of excellent restaurants and cafes, its dozens of theaters and performance halls, its outstanding museums, its many movie theaters, and its excellent bookstores. They rarely let the weather stand in the way of having a good time, and neither should you. \u201c<\/p>\n<p>So is that true, do Seattleites rarely let the weather stand in the way of having a good time? Let\u2019s put it this way: there\u2019s a reason why they tell you that shouldn\u2019t believe everything you read on the Internet.<\/p>\n<p>Well, except for this column, of course.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I schedule a meeting to occur every day, Monday through Friday, for two weeks?&#8212; GB Hey, GB. As it turns out, the Scripting Guy who writes this column has not moved to some place where it doesn\u2019t snow in April. That\u2019s not because the Seattle area didn\u2019t get the predicted [&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-55723","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 schedule a meeting to occur every day, Monday through Friday, for two weeks?&#8212; GB Hey, GB. As it turns out, the Scripting Guy who writes this column has not moved to some place where it doesn\u2019t snow in April. That\u2019s not because the Seattle area didn\u2019t get the predicted [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55723","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=55723"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55723\/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=55723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=55723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=55723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}