如何将Excel的前身数据导出到MS项目?

发布于 2025-01-21 19:59:38 字数 2733 浏览 1 评论 0原文

我的工作簿中有四列。例如,ID列可以忽略。

ID任务名称资源名称前任
1task1employee12
2subtask1employee2
3task2employee14,5
4subtask2employee2 employee2
5subtask3employeee2

我希望创建一个Excel宏以将内容导出到MS项目中。

我只能在网络中找到有关转移任务的共享。

我的代码,信用#madschedules,仅包括任务。

Sub createNewMSPFromExcelData()

' First go turn on the MS Project reference library

' Declare variables
Dim pjApp As MSProject.Application
Dim pjProject As MSProject.Project
Dim pjtasklist As MSProject.Tasks
Dim pjtask As MSProject.Task
'Dim pjpredlist As MSProject.TaskDependencies
'Dim pjpredlist As TaskDependencies
Dim pjpred As TaskDependency
Dim xlrange As Range
Dim xlrow As Long
Dim counter As Integer

'open MS Project application
Set pjApp = New MSProject.Application
pjApp.Visible = True

' Add a new project file
Set pjProject = pjApp.Projects.Add
Set pjtasklist = pjProject.Tasks


'Loop through all the Excel Data in the worksheet
counter = 2
Do Until Cells(counter, 1) = ""
    Debug.Print Cells(counter, 1).Value & "   " & Cells(counter, 2).Value & "   " & Cells(counter, 3).Value

    ' Add new task into MS Project from Excel Value
    pjtasklist.Add (Cells(counter, 2).Value)
    pjpred.Add (Cells(counter, 3).Value)

    counter = counter + 1
Loop

MsgBox ("There are " & pjtasklist.Count & vbNewLine & _
       " tasks in our new project")

End Sub

MS项目中的预期数据

为了回答有关前任的回答,我目前正在使用电子示意图设计的项目,该项目涉及多层结构。因此,要在层次结构上进行工作,我需要确保在继续下一个级别之前进行子层次结构活动,因此,我将前辈的细节从示意图中衍生成Excel。

I have four columns in my workbook. e.g. ID Column can be ignored.

IDTask NameResource NamesPredecessors
1Task1Employee12
2SubTask1Employee2
3Task2Employee14,5
4SubTask2Employee2
5SubTask3Employee2

I am looking to create an Excel macro to export the contents into MS Project.

I can only find sharing in the web about transferring the Task.

My code, credit to #madschedules, only includes Tasks.

Sub createNewMSPFromExcelData()

' First go turn on the MS Project reference library

' Declare variables
Dim pjApp As MSProject.Application
Dim pjProject As MSProject.Project
Dim pjtasklist As MSProject.Tasks
Dim pjtask As MSProject.Task
'Dim pjpredlist As MSProject.TaskDependencies
'Dim pjpredlist As TaskDependencies
Dim pjpred As TaskDependency
Dim xlrange As Range
Dim xlrow As Long
Dim counter As Integer

'open MS Project application
Set pjApp = New MSProject.Application
pjApp.Visible = True

' Add a new project file
Set pjProject = pjApp.Projects.Add
Set pjtasklist = pjProject.Tasks


'Loop through all the Excel Data in the worksheet
counter = 2
Do Until Cells(counter, 1) = ""
    Debug.Print Cells(counter, 1).Value & "   " & Cells(counter, 2).Value & "   " & Cells(counter, 3).Value

    ' Add new task into MS Project from Excel Value
    pjtasklist.Add (Cells(counter, 2).Value)
    pjpred.Add (Cells(counter, 3).Value)

    counter = counter + 1
Loop

MsgBox ("There are " & pjtasklist.Count & vbNewLine & _
       " tasks in our new project")

End Sub

Expected data in MS Project
enter image description here

To answer about the predecessors, I am currently doing a project with electronic schematic design which deals with multi hierarchies. Hence to work on the hierarchy, I need to ensure the sub-hierarchy activities are done before I can proceed with the next level, hence I have the predecessors details derived from the schematic into Excel.

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

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

发布评论

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

评论(1

浸婚纱 2025-01-28 19:59:38

添加任务然后设置任务属性的关键是在添加任务对象后获取对任务对象的引用。因此,而不是:

pjtasklist.Add (Cells(counter, 2).Value)

在进行

Set pjtask = pjtasklist.Add (Cells(counter, 2).Value)
pjtask.ResourceNames = Cells(counter, 3).Value

进一步之前,需要清楚地了解任务,子任务和前任。在调度中,A 子任务被认为是摘要任务下的任务。摘要任务用于分组项目的任务的相关子集。摘要任务的开始和结束日期是根据其子任务的最早开始和最新完成的。

前任是必须在启动另一个任务之前必须发生的任务。前身任务几乎应该始终首先输入,以便时间表按时间顺序读取。因此,很少见到具有前身ID值高于其自己的任务。取而代之的是,Excel表会更好,例如OL = OL = OUTLINELEVEL:

ID任务名称资源名称前任OL
1task1 employee1employee1employee1
1subtask1emplyee22
3task2employee1
4subtask2emplyeee22
5subtask3emplyeee24 emplyeee2 42

this this this this this the典型的时间表结构,例如典型的时间表结构此:

最后,这是将上表变成时间表的代码:

Sub createNewMSPFromExcelData()

Dim pjApp As MSProject.Application
Dim pjProject As MSProject.Project
Dim pjtasklist As MSProject.Tasks
Dim pjtask As MSProject.Task
Dim counter As Integer

Set pjApp = New MSProject.Application
pjApp.Visible = True

Set pjProject = pjApp.Projects.Add
Set pjtasklist = pjProject.Tasks

counter = 2
Do Until Cells(counter, 1) = ""

    Set pjtask = pjtasklist.Add(Cells(counter, 2).Value)
    pjtask.ResourceNames = Cells(counter, 3).Value
    pjtask.Predecessors = Cells(counter, 4).Value
    pjtask.OutlineLevel = Cells(counter, 5).Value

    counter = counter + 1
Loop

MsgBox ("There are " & pjtasklist.Count & vbNewLine & _
       " tasks in our new project")

End Sub

The key to adding tasks and then setting task properties is to get a reference to the task object after it's added. So instead of:

pjtasklist.Add (Cells(counter, 2).Value)

do

Set pjtask = pjtasklist.Add (Cells(counter, 2).Value)
pjtask.ResourceNames = Cells(counter, 3).Value

Before going any further, however, clarity is needed regarding tasks, subtasks, and predecessors. In scheduling, a subtask is considered to be a task under a summary task. A summary task is used to group a related subset of the tasks for the project. The summary task's start and finish dates are calculated based on the earliest start and latest finish of its subtasks.

Predecessors are tasks that must happen before another task can start. Predecessor tasks should almost always be entered first so that the schedule reads in chronological order. Therefore it is extremely rare to see a task with a predecessor ID value higher than its own. Instead, the Excel table would be better like this where OL = OutlineLevel:

IDTask NameResource NamesPredecessorsOL
1Task1Employee11
2SubTask1Employee22
3Task2Employee11
4SubTask2Employee22
5SubTask3Employee242

This yields the typical schedule structure like this:

sample schedule

And finally, here is the code to turn the table above into the schedule:

Sub createNewMSPFromExcelData()

Dim pjApp As MSProject.Application
Dim pjProject As MSProject.Project
Dim pjtasklist As MSProject.Tasks
Dim pjtask As MSProject.Task
Dim counter As Integer

Set pjApp = New MSProject.Application
pjApp.Visible = True

Set pjProject = pjApp.Projects.Add
Set pjtasklist = pjProject.Tasks

counter = 2
Do Until Cells(counter, 1) = ""

    Set pjtask = pjtasklist.Add(Cells(counter, 2).Value)
    pjtask.ResourceNames = Cells(counter, 3).Value
    pjtask.Predecessors = Cells(counter, 4).Value
    pjtask.OutlineLevel = Cells(counter, 5).Value

    counter = counter + 1
Loop

MsgBox ("There are " & pjtasklist.Count & vbNewLine & _
       " tasks in our new project")

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