如何使用VBA代码在MPP中添加年度例外?

huangapple go评论59阅读模式
英文:

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

问题

我期待的代码与此问题中类似:
https://stackoverflow.com/questions/70794737/insert-exceptions-into-resource-calendar

在MPP界面中,您只需选择“yearly”单选按钮,并设置例外情况(放假)将重复发生的日期和月份,但我需要通过开发者模式的代码来执行,以便以后扩展功能。

我尝试使用了类型2属性:
pjYearlyMonthDay	2	例外情况的重复模式为每年在指定的某月某日,例如12月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"


但我遇到了错误1101。
Microsoft的文档在这里,但我无法弄清楚:
https://learn.microsoft.com/en-us/office/vba/api/project.exceptions.add
https://learn.microsoft.com/en-us/office/vba/api/project.pjexceptiontype
英文:

I expect the code to be similar to the question here:
https://stackoverflow.com/questions/70794737/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

答案1

得分: 1

以下是添加此类年度异常的正确语法:

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

Month和MonthDay参数需要设置为Long类型。请参阅Exceptions.Add方法。

英文:

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.

huangapple
  • 本文由 发表于 2023年6月29日 20:04:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定