循环遍历 MS Project 中的列

Looping though column in MS Project

我正在尝试使用 Excel 中的 VBA 将所有数据从 MS 项目导入到 Excel。

Set aProg = appProj.ActiveProject

appProj.OutlineShowAllTasks
j = 2
For Each t In aProg.Tasks
    If (Not t Is Nothing) Then
Cells(j, 5).Value = t.Start
Cells(j, 6).Value = t.Task Name
Cells(j, 7).Value = t.%complete


j =j+1
end if

下一个

如果列 name/field 名称没有任何特殊字符或空白,则代码可以正常工作。 谁能告诉我如何使用空格或特殊字符(如 "t.Task Name" 或 "t.%complete"

来引用字段名称

在编写代码时使用 Early Binding so you have IntelliSense (more info)。这样你就可以声明 t As MSProject.Task,当你键入 t 后跟一个句点时,你会得到一个属性和方法的下拉列表。

对于您的具体情况,您需要的属性是 t.TaskNamet.PercentComplete