我从docs.microsoft.com复制了一些VBA代码,以便更好地了解MS项目中摘要任务对象的工作原理。然而,我在原代码上收到运行时91错误,请看下文。
Sub CheckAssignmentsOnSummaryTasks()
Dim tsk As Task
Dim message As String
Dim numAssignments As Integer
Dim numSummaryTasksWithAssignments As Integer
Dim msgStyle As VbMsgBoxStyle
message = ""
numSummaryTasksWithAssignments = 0
For Each tsk In ActiveProject.Tasks
If tsk.Summary Then
numAssignments = tsk.Assignments.Count
If numAssignments > 0 Then
message = message & "Summary task ID (" & tsk.ID & "): " & tsk.Name _
& ": " & numAssignments & " assignments" & vbCrLf
numSummaryTasksWithAssignments = numSummaryTasksWithAssignments + 1
End If
End If
Next tsk
If numSummaryTasksWithAssignments > 0 Then
message = "There are " & numSummaryTasksWithAssignments _
& " summary tasks that have assignments." & vbCrLf & vbCrLf & message
msgStyle = vbExclamation
Else
message = "No summary tasks have assignments."
msgStyle = vbInformation
End If
MsgBox message, msgStyle, "Summary Task Check"
End Sub
运行时91错误标识了这一行。
If tsk.Summary Then".
在上网查询了可能的原因后,我安装了MS project。
任何帮助是什么原因导致这将是非常感激的,因为我已经注意到同样的错误在另一个docs.microsoft.com VBA脚本。
先谢谢你。
检查 tsk
因为没有 Nothing
,像这样。
For Each tsk In ActiveProject.Tasks
If Not tsk is Nothing Then
If tsk.Summary Then