【发布时间】:2020-07-01 07:21:45
【问题描述】:
在 Excel 中,我在“A”列中的 ID 编号从第二行开始(第一行 = 标题)。在“T”列中,我在同一行上有该 ID 的持续时间。
在 MS Project 中,我有一个 ID 列和一个空的持续时间列。我想在正确的 ID 行上添加从 excel 到 MS Project 的持续时间。
我想我可以通过使用任务和 For..To 循环来做到这一点。我将需要使用 excel 中的 ID 在 MS Project 中查找任务,然后在 MS Project 中的相应任务中写入来自 excel 的持续时间。到目前为止,在一些帮助下,我拥有的代码是:
'Find duration and assign to ID in Excel
For i = 2 To lastRow
date1 = .Cells(i, 15)
date2 = .Cells(i, 16)
If .Cells(i, 18).Value = "No" Then
answer = DateDiff("n", date1, date2)
.Cells(i, 20) = answer
End If
durationID = .Cells(i,1).Value
Next i
'Open MS Project and add Duration column
set wb = ActiveWorkBook
Set ws = wb.Sheets("Task_Table1")
Set appProj = CreateObject("Msproject.Application")
appProj.FileOpen "File1.mpp"
Set aProg = appProj.ActiveProject
appProj.Visible = True
lastTask = ActiveProject.Tasks.Count
taskID = ActiveProject.Tasks.ID
'Load Durations into MS Project to appropriate ID task
lastTask = ActiveProject.Tasks.Count
For i = 1 to lastTask
If taskID = Application.Workbooks("File1").Sheets("Task_Table1").Cells(i, 1).Value Then
answer.Copy
appProj.SelectCell.ActiveCell
end if
Next i
【问题讨论】:
标签: excel vba ms-project