Bogdan
Bogdan

Reputation: 13

How to add a yearly exception inside a MPP using VBA code?

I expect the code to be similar to the question here: Insert exceptions into Resource Calendar

From the MPP interface you just select the "yearly" radio button and set the day and month in which the exception (day off work) will be repeated, but I need to do it with from developer mode code to expand the functionality later.

I tried using the Type 2 property for: pjYearlyMonthDay 2 The exception recurrence pattern is yearly on a specified day of a month, for example on December 24.

Dim CalName As String
CalName = ActiveProject.Calendar.Name
ActiveProject.BaseCalendars(CalName).Exceptions.Add Type:=2, Start:="5/01/2023", Occurrences:=10, Name:="TEST", MonthDay:="5 January"

But I have error 1101. Microsoft documentation here but I can't figure it out: https://learn.microsoft.com/en-us/office/vba/api/project.exceptions.add https://learn.microsoft.com/en-us/office/vba/api/project.pjexceptiontype

Upvotes: 1

Views: 103

Answers (1)

Rachel Hettinger
Rachel Hettinger

Reputation: 8442

Here is the correct syntax for adding this kind of yearly exception:

ActiveProject.Calendar.Exceptions.Add Type:=2 _
    , Start:="05/01/2023", Occurrences:=10, Name:="TEST", Month:=1, MonthDay:=5

The Month and MonthDay parameters need to be set and they are both Long. See Exceptions.Add method.

Upvotes: 1

Related Questions