VBA Excel 到 MS 项目

发布于 2025-01-21 03:20:24 字数 535 浏览 2 评论 0原文

VBA 新手,我成功地从 Excel 导入和读取任务列表和资源,在 Excel 中执行 VBA 并将这些记录插入到 MS Project 中。我正在考虑设置 ActiveProject.Resources.Standardrate = "100p/h",但是出现错误。

正在应用的代码(归功于之前为 Stackoverflow 上的其他相关问题提供的以下代码的答案)。

If Not ExistsInCollection (newproject.Resources, strResource) Then
  newproject.resources.add.name = StrResource  <-- This works, resources are added.

  ' However, inserting the following line:

  newproject.resources.standardrate = "100p/h"  <-- It errors here

End if

非常感谢任何帮助 - 谢谢。

New to VBA, I am successfully importing and reading a Task List and Resources from Excel, executing VBA in Excel and inserting these records into MS Project. I am looking at setting the ActiveProject.Resources.Standardrate = "100p/h", however I am getting an error.

The code being applied (credit to previous answers provided to other related questions on Stackoverflow for the following code).

If Not ExistsInCollection (newproject.Resources, strResource) Then
  newproject.resources.add.name = StrResource  <-- This works, resources are added.

  ' However, inserting the following line:

  newproject.resources.standardrate = "100p/h"  <-- It errors here

End if

Any assistance is greatly appreciated - Thank you.

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

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

发布评论

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

评论(1

木有鱼丸 2025-01-28 03:20:24

该代码需要进行较小的修改以获取对新添加的资源的引用,以便可以更新标准率。

该代码还演示了如何处理逗号限制资源列表的情况,而不是单个资源。

Dim t As Task
Set t = NewProject.Tasks.Add("New task 1")

Dim StrResource As String
StrResource = "Resource 1,Resource 2,Resource 3"
Dim arrRes As Variant
arrRes = Split(StrResource, ",")

Dim i As Variant
For Each i In arrRes
    If Not ExistsInCollection(NewProject.Resources, i) Then
        Dim r As Resource
        Set r = NewProject.Resources.Add(i)
        r.StandardRate = 100
    End If
    t.Assignments.Add , ActiveProject.Resources(i).UniqueID
Next i

The code needed a minor modification to get a reference to the newly-added resource so that the StandardRate can then be updated.

This code also demonstrates how to handle the case of a list of comma-delimited resources rather than a single one.

Dim t As Task
Set t = NewProject.Tasks.Add("New task 1")

Dim StrResource As String
StrResource = "Resource 1,Resource 2,Resource 3"
Dim arrRes As Variant
arrRes = Split(StrResource, ",")

Dim i As Variant
For Each i In arrRes
    If Not ExistsInCollection(NewProject.Resources, i) Then
        Dim r As Resource
        Set r = NewProject.Resources.Add(i)
        r.StandardRate = 100
    End If
    t.Assignments.Add , ActiveProject.Resources(i).UniqueID
Next i
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文