在vba(excel到mpp文件)中缩进mpp文件(Ms项目文件)中的任务



我是一名VB开发人员,第一次使用MPP文件。

我的代码从Excel中读取数据,并成功地将某一列和行写入mpp文件。

1) 如何在MPP文件中选择单个单元格,因为我有一个场景,我将与下一行单元格进行比较,并进行一些操作

2) 为什么我们不能在mpp文件中自定义列(如计算机名称、光盘名称等),它会给出错误

3) 如何缩进单元格将一个单元格作为主单元格保留在其下方,并且它应该遍历循环

删除所有任务的代码

For Each oSubTasks In oTasks
If Not oSubTasks Is Nothing Then
oSubTasks.Delete
End If
Next oSubTasks

获取列值的代码

For Each oSubTasks In oTasks
'if the frist row is blank
If oSubTasks.GetField(FieldNameToFieldConstant("Duration")) = "" Then Exit For
If oSubTasks.GetField(FieldNameToFieldConstant("Duration")) <> "" Then
Mpplastrow = Mpplastrow + 1
End If
Next oSubTasks

自定义列的代码获取错误

If oSubTasks.GetField(FieldNameToFieldConstant("computer name")) = sh1.Cells(rw, primecol).Value Then
'    oTask.SetField FieldID:=oApp.FieldNameToFieldConstant("computer name"), Value:=sh1.Cells(rw, primecol).Value
'Else
'    oTask.SetField FieldID:=oApp.FieldNameToFieldConstant("computer name"), Value:=sh1.Cells(rw, primecol).Value
'End If

要读取每个MSP任务的缩进级别,并能够在内部(或外部)进行缩进,请尝试以下代码:

Option Explicit
Sub IndentTasks()
Dim Tsk As Task
For Each Tsk In ThisProject.Tasks            
Select Case Tsk.OutlineLevel '<-- read the current taks Outline Level
Case 1
If Tsk.ID <> 1 Then
Tsk.OutlineIndent '<-- indent inside (to the right)
End If
Case Is > 6 '<-- don;t want your Project to be too indented inside
Tsk.OutlineOutdent '<-- indent outside (to the left)
End Select
Next Tsk
End Sub

最新更新