【发布时间】:2019-03-11 08:50:07
【问题描述】:
我设法制作了一个不错的脚本,可以从 excel 中的选定表生成 MS 项目文件。我现在正在寻求帮助,使其更有用。我想在 Excel 中特定表格的每个主要任务下插入里程碑。每个主要任务都有一个对应的里程碑表。
Sub MSPexport()
Dim pjapp As Object
Dim strValue, strWorktime, strMilestone As String
Dim newproj
Set pjapp = CreateObject("MSProject.application")
If pjapp Is Nothing Then
MsgBox "Project is not installed"
End
End If
pjapp.Visible = True
Set newproj = pjapp.Projects.Add
Set ActiveProject = newproj
pjapp.NewTasksStartOn
'insert tasks here
For I = 3 To 8 'currently I am pointing to the range A3:A:8 - would like to make it a named range instead - ie "Maintasks" - how to do this?
strValue = Worksheets("Planning").Range("A" & I)
newproj.Tasks.Add (strValue)
'Insert predecessor if not first task
If I <> 3 Then
newproj.Tasks(I - 2).Predecessors = (I - 3)
End If
'here I would like to insert milestones as subtasks
For M = 3 to 5 ' this I also would like to be a named range and also I need to check for or lookup the correct main task and the corresponding milestone list
strMilestone = Worksheets("Milestones").Range("C" & M)
newproj.Tasks.Add (strMilestone)
newproj.Tasks(M - 2).Duration = 0
newproj.Tasks(M - 2).OutlineIndent
newproj.Tasks(M - 2).Predecessors = (I - 26)
Next M
Next I
End Sub
【问题讨论】:
标签: excel vba ms-project