Microsoft KB Archive/126987

Exceptions Lost After Running Macro to Edit Calendar

PSS ID Number: Q126987 Article last modified on 08-24-1995

4.00 | 4.00

WINDOWS | MACINTOSH

= SYMPTOMS =

In Microsoft Project, when you use the Change Working Time dialog box to change the working days for a month in the base calendar, the month(s) following the month that you edit may lose their exceptions if you make this change after you run a macro that edits the base calendar.

= CAUSE =

This behavior occurs if you use the Working property in a Visual Basic, Applications Edition, macro to set the working or nonworking days for a date range on the base calendar. The problem occurs if the date range you specify extends beyond one month. After you run the macro, if you use the Change Working Time dialog box to change the working days for the first month in the range that you modified, the exceptions for the following months in the range are lost.

For example, if you run a macro that contains the following command

ActiveProject.BaseCalendars(1).Period(&quot;3/29/95&quot;, &quot;5/5/95&quot;).Working = _ False if you open the Change Working Time dialog box, and change the working days in the month of March 1995, the exceptions for the months of April 1995 and May 1995 are lost. That is, the days in the months of April 1995 and May 1995 are set back to nonworking.

= WORKAROUNDS =

To work around this problem, use any of the following methods.

Method 1
Use the BaseCalendarEditDays Method to edit the base calendar as in the following example:

Sub ChangeWorkDays ’ Set all days in the range 3/29/95 to 5/5/95 as nonworking BaseCalendarEditDays Name:=“Standard”, startDate:=“3/29/95”, _ endDate:=“5/5/95”, Working:=False End Sub

Method 2
Use the Working Property of the Period object with one month intervals. For example, use the following three commands to set the Working property to the value False for the entire range 3/29/95 to 5/5/95 instead of one command:

Sub ChangeWorkDays ActiveProject.BaseCalendars(1).Period(“3/29/95”,“3/31/95”).Working =  False ActiveProject.BaseCalendars(1).Period(“4/1/95”,“4/30/95”).Working =  False ActiveProject.BaseCalendars(1).Period(“5/1/95”,“5/5/95”).Working = _ False End Sub

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided ‘as is’ and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code–comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the “Programming Style in This Manual” section in the “Document Conventions” section of the “Visual Basic User’s Guide.”

= STATUS =

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

= MORE INFORMATION =

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

ARTICLE-ID: Q126986 TITLE : Can’t Change Working Time After Running Macro to Edit Calendar

= REFERENCES =

For more information about the BaseCalendars Method, choose the Search button in the Visual Basic Reference and type:

BaseCalendars For more information about the Working Property, choose the Search button in the Visual Basic Reference and type:

Working For more information about the BaseCalendarEditDays Method, choose the Search button in the Visual Basic Reference and type:

BaseCalendarEditDays KBCategory: kbprg kbcode KBSubcategory:

= Additional reference words: 4.00 =

Copyright Microsoft Corporation 1995.