如何获取员工(资源)的工作日和缺勤天数?

发布于 2024-12-09 23:09:12 字数 342 浏览 1 评论 0原文

如何从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尛丟丟 2024-12-16 23:09:12

您需要查看 Resource 对象来查找工作日和非工作日:

ActiveProject.Resources.Item(1).Calendar

在这个简单的示例中,我们将选取项目中的第一个资源并拉出它的关联日历。

资源日历将有一个从中继承的基准日历:

...Calendar.BaseCalendar

资源日历和基准日历都定义工作日、工作周和例外情况。例外情况通常是如何定义缺勤时间的……即,它们是正常工作模式的例外情况:

...Calendar.WorkWeeks
...Calendar.WeekDays
...Calendar.Exceptions

You need to look at the Resource object to find the working and non-working days:

ActiveProject.Resources.Item(1).Calendar

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:

...Calendar.BaseCalendar

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:

...Calendar.WorkWeeks
...Calendar.WeekDays
...Calendar.Exceptions
空城缀染半城烟沙 2024-12-16 23:09:12

答案已经提供了入门信息,但实际上并没有回答问题。如前所述,“异常”确实是如何定义缺勤时间段的,但要从异常对象中确定给定日期是否为缺勤日,将需要大量的解析代码。

根据经验确定工作日会更简单、更可靠。假设变量“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文