Home > Net >  pjweekday constants for weekday exceptions for multiple days
pjweekday constants for weekday exceptions for multiple days

Time:09-22

I've been trying to import & export workday exceptions of MS-Project from/to Excel. Daily, monthly or yearly exceptions are no problem, but weekly exceptions do cause me some trouble:

By recording, I understand that for each combination of several weekdays selected (via the tick-boxes) the property "pjWeekday" (or DaysOfWeek in the recorded code) is a specific Integer (6, 10 & 18 in the examples below).

Example of recorded code:

ActiveProject.BaseCalendars("Copy of Standard").Exceptions.Add Type:=6, Start:="01.01.2022", Finish:="18.01.2022", Name:="TestWeekly1", Period:=1, DaysOfWeek:=6
    ActiveProject.BaseCalendars("Copy of Standard").Exceptions.Add Type:=6, Start:="01.02.2022", Finish:="02.02.2022", Name:="TestWeekly2", Period:=1, DaysOfWeek:=10
    ActiveProject.BaseCalendars("Copy of Standard").Exceptions.Add Type:=6, Start:="01.03.2022", Finish:="03.03.2022", Name:="TestWeekly3", Period:=1, DaysOfWeek:=18

Is there any way to get a list of all integers for all combinations (or is an algorithm behind it) without recording all different possibilities ?

Greatful for any advice, Chris

CodePudding user response:

Enumerated constants are documented on the Microsoft site; here's the list for pjWeekDay.

The Exceptions.Add method states the DaysOfWeek parameter is "The days on which the exception occurs. Can be a combination of PjWeekday constants." My testing indicates this is only a partial truth.

It appears that the DaysOfWeek values are not PjWeekday constants but rather powers of 2 that can be aggregated. For example, if the weekly exception is for Mondays, the DaysOfWeek = 2 (2^1) and for Thursdays it would be 16 (2^4). And if the exception is for Mondays and Wednesdays, the value would be 10 (2^1 2^3).

The formula is: the sum of 2 ^ (PjWeekday constant - 1) for each weekday in the exception.

  • Related