0

我有一个简单的 MS Project 文件 (2007),只有几个任务。我还创建了一个名为的自定义字段VBATest,并针对两个项目任务为该自定义字段分配了值。

我想像这样检索项目任务列表和分配给自定义字段的值;

ProjectTask | VBATest <--Custom field
------------|--------
Task1       | vba1
Task2       | vba2

我从 Access 2007 VBA 执行此操作,因为这是最终代码的结束位置。我可以让它大部分工作,但我似乎无法从 Assignments 对象中读取自定义字段值。你有什么想法?谢谢

这是我到目前为止所做的。

Sub LoadProjectFile()

Dim pjApp As MSProject.Application
Dim FileToOpen
Dim Proj As MSProject.Project
Dim Project_Task As Task
Dim fd As FileDialog

Set pjApp = New MSProject.Application

If pjApp Is Nothing Then
MsgBox "Project is not installed"
End
End If

pjApp.Visible = True
AppActivate "Microsoft Project"

Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Filters.Clear
fd.Filters.Add "Microsoft Project Files", "*.mpp"
fd.AllowMultiSelect = False
fd.Show
If (fd.SelectedItems.Count = 0) Then
    'Application.GetOpenFilename("Microsoft Project Files (*.mpp), *.mpp")
    pjApp.Quit
    Set pjApp = Nothing
    Exit Sub
End If

pjApp.FileOpen fd.SelectedItems(1)
Debug.Print "Project_Task_Name~CustomField"

Dim ass As Assignment
For Each Project_Task In pjApp.ActiveProject.Tasks
            If Not Project_Task Is Nothing Then

                For Each ass In Project_Task.Assignments
                    assignCFVal = assignCFVal & "," & ass.VBATestField '<<PROBLEM Line
                Next ass

               Debug.Print Project_Task.Name & "~" & assignCFVal
               assignCFVal = ""
            End If
        Next Project_Task

pjApp.FileClose pjDoNotSave
pjApp.Quit
Set pjApp = Nothing

End Sub
4

1 回答 1

0

事实证明,我不需要为此使用 Assignments 对象。SetField 方法将返回我需要的内容,如下所示;

For Each Project_Task In pjApp.ActiveProject.Tasks
            If Not Project_Task Is Nothing Then
              assignCFVal = Project_Task.SetField(FieldNameToFieldConstant("VBATestField"))
              Debug.Print Project_Task.Name & "~" & assignCFVal
            End If
Next Project_Task
于 2011-08-18T16:53:42.380 回答