如何获取员工(资源)的工作日和缺勤天数?
如何从 MS-Project 使用 VBA 获取员工的工作天数和缺勤天数? (员工是资源)
一些附加信息:
我知道如何获取任务
Dim ts as Tasks
Set ts = ActiveProject.Tasks
,我知道如何从我的项目文件中获取资源:
Dim rs as Resources
Set rs = ActiveProject.ressources
但我没有找到一种(简单的)方法从这个变量中获取工作和缺勤天数。
How do I get the work and absence days of an employee with VBA from MS-Project? (an employee is a ressource)
Some additional infos:
I know how to get tasks
Dim ts as Tasks
Set ts = ActiveProject.Tasks
and I know how to get ressources from my project file:
Dim rs as Resources
Set rs = ActiveProject.ressources
but I do not find a (trivial) way to get work and absence days from this variables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要查看 Resource 对象来查找工作日和非工作日:
在这个简单的示例中,我们将选取项目中的第一个资源并拉出它的关联日历。
资源日历将有一个从中继承的基准日历:
资源日历和基准日历都定义工作日、工作周和例外情况。例外情况通常是如何定义缺勤时间的……即,它们是正常工作模式的例外情况:
You need to look at the Resource object to find the working and non-working days:
In this trivial example we're picking up the first resource in the project and pulling out it's associated Calendar.
A resource calendar will have a base calendar from which it inherits:
and both the resource calendar and the base calendar define working days, working weeks and exceptions. Exceptions are typically how periods of absence are defined... i.e. they are exceptions to the normal pattern of work:
答案已经提供了入门信息,但实际上并没有回答问题。如前所述,“异常”确实是如何定义缺勤时间段的,但要从异常对象中确定给定日期是否为缺勤日,将需要大量的解析代码。
根据经验确定工作日会更简单、更可靠。假设变量“cal”是有问题的日历,声明一个 long 类型的变量(例如“d”),然后从某个开始日期循环到某个结束日期-1,并使用 Application.datedifference (d ,d+1,校准)。非工作日的收益为 0。
The answer already provided information to get one started, but does not actually answer the question. As stated, "Exceptions" are indeed how periods of absence are defined but to determine if a given date is an absence day from the exception object will take a not-insignificant amout of parsing code.
It would be a lot simpler and much more reliable to determine workdays empirically. Assuming variable "cal" is the calendar in question declare a variable (say "d") of type long then loop from some start date to some end date-1 and determine if that date is a workday or not using Application.datedifference (d, d+1, cal). A non work day will yield 0.