TimeScaleData 的更快替代方案,用于更新特定时间段内的分配工作

发布于 2025-01-15 14:53:57 字数 835 浏览 4 评论 0原文

我正在使用 VBA 来更新项目中的实际工作。从外部 csv 表中,我获得每个任务、资源和每周的实际工时,然后需要以相同的三个维度将其输入到项目中。

我发现很多东西都可以在 Project 中以两种截然不同的方式进行编码,具体取决于我是从录制宏中获得灵感,还是从探索对象浏览器中的方法和属性中获得灵感。对于此操作,除了在“任务使用情况”视图的“时间刻度”窗口中更新实际工作时通过录制宏所学到的方法之外,我没有找到任何其他方法。这给了我 TimeScaleData 方法。

这是我的代码的简化版本。变量 MyStartDateString、MyEndDateString 和 MyActualWork 在别处定义。

dim t as Task
dim a as Assignment    
For Each t in ActiveProject.Tasks
     For Each a in t.Assignments
          a.TimeScaleData(StartDate:=MyStartDateString, _
          EndDate:=MyEndDateString, Type:=10, TimeScaleUnit:=3, _ 
          Count:=1).Item(1).Value = MyActualWork
     Next a
Next t

在这一部分之前实际上还有很多事情要做,我每周都会在 csv 文件中逐步进行操作,并将任务和资源的名称与 Project 中的名称和资源进行匹配,等等,但这是其中的关键部分。我发现,在一个包含大约 1000 个 TimeScaleData 操作的项目中,整个过程大约需要 45 秒,速度慢得令人恼火。有没有更快更优雅的方法?

非常感谢您的帮助!

I'm using VBA to update actual work in my projects. From an external csv sheet, I get actual work per task, resource and week, which then needs to be fed into Project in the same three dimensions.

I find that many things can be coded in two very different ways in Project, depending on whether I get the inspiration from recording a macro, or from exploring methods and properties in the Object Browser. For this operation, I haven't found any other way than what I learned by recording a macro while I update actual work in the Time Scale window in Task Usage view. This has given me the TimeScaleData method.

Here is a simplified version of my code. The variables MyStartDateString, MyEndDateString and MyActualWork are defined elsewhere.

dim t as Task
dim a as Assignment    
For Each t in ActiveProject.Tasks
     For Each a in t.Assignments
          a.TimeScaleData(StartDate:=MyStartDateString, _
          EndDate:=MyEndDateString, Type:=10, TimeScaleUnit:=3, _ 
          Count:=1).Item(1).Value = MyActualWork
     Next a
Next t

There is actually a lot more going on before this part, where I step through each week in the csv file and match the name of the task and resource with those in Project so on, but this is the critical part of it. I have found that in a project with around 1000 of these TimeScaleData operations, the whole thing takes around 45 seconds, which is annoyingly slow. Is there a faster and more elegant way?

Thanks a lot for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

酒与心事 2025-01-22 14:53:57

是的,在 Project 中通常有两种方法可以完成同一件事,但在本例中只有一种。但是,它应该有助于减少对 TimeScaleData 的调用 方法 - 每个作业只有一个,然后循环遍历 TimeScaleValues 集合并为每个 TimeScaleValue 对象。

另外,传入开始日期和结束日期的日期变量,而不是字符串。并关闭计算ScreenUpdating

查看类似的堆栈溢出帖子,例如使用 .net 的项目中的 TimeScaleData

Yes, there are often two ways of doing the same thing in Project, but in this case there is only one. However, it should help to make fewer calls to the TimeScaleData method--only one per assignment and then loop through the TimeScaleValues collection and set the Value property for each TimeScaleValue object.

Also, pass in date variables for the start and end dates, rather than strings. And turn off Calculation and ScreenUpdating.

Look at similar stack overflow posts such as TimeScaleData in Project using .net.

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