通过 Excel 使用 VBA 在 MS Project 中的特定位置添加任务

发布于 2025-01-16 19:00:15 字数 506 浏览 2 评论 0原文

我有包含所有当前任务的 Excel 文件。新任务可以添加到任何位置。我想通过添加缺少的任务来从 Excel 更新我的 MS Project 文件。使用 .Tasks.Add("name from Excel") 将作为 MS Project 底部的新任务。如何使用 Excel 中的 VBA 在中间的特定位置添加新任务?我可以在 Excel 的 VBA 代码中使用 SelectRowInsertTask 吗?

*编辑 忘了提及,.Tasks.Add 不允许我使用第二个参数,就像文档中所说的那样。

With mpp
    .Tasks.Add ("name from Excel", RowNumber)
End With

此代码会将 .Tasks.Add ("name from Excel", RowNumber) 行显示为红色。如果我删除第二个参数,那就很好并且可以工作。

I have and Excel file with all current tasks. New tasks maybe be added at any position. I want to update my MS Project file from Excel by adding missing tasks. Using .Tasks.Add("name from Excel") will as a new Task in MS Project at the bottom. How can i add new Task at a specific location in the middle using VBA from Excel? Can I use SelectRow and InsertTask in VBA code from Excel somehow?

*EDIT
Forgot to mention, .Tasks.Add does not let me use a 2nd argument, like it says in documentation.

With mpp
    .Tasks.Add ("name from Excel", RowNumber)
End With

This code will have the line with .Tasks.Add ("name from Excel", RowNumber) in red. If i remove the 2nd argument, it's fine and works.

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

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

发布评论

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

评论(1

醉梦枕江山 2025-01-23 19:00:16

快速查看文档 Tasks.Add 显示该方法采用可选的第二个参数Before

任务在其包含的集合中的位置。默认
value 是集合中最后一项的位置。 (数据类型
长)

利用第二个参数并传入应在其之前添加新任务的任务 ID。例如:

With mpp
    .Tasks.Add "name from Excel", RowNumber
End With

或者

Dim t As MSProject.Task
With mpp
    Set t = .Tasks.Add("name from Excel", RowNumber)
End With

A quick check of the docs for Tasks.Add shows that the method takes an optional second argument Before:

The position of the task in its containing collection. The default
value is the position of the last item in the collection. (data type
Long)

Utilize the second argument and pass in the ID of the task before which the new task should be added. For example:

With mpp
    .Tasks.Add "name from Excel", RowNumber
End With

Or

Dim t As MSProject.Task
With mpp
    Set t = .Tasks.Add("name from Excel", RowNumber)
End With
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文