【发布时间】:2020-08-10 22:45:40
【问题描述】:
我从 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 项目。
如果我在另一个 docs.microsoft.com VBA 脚本上发现了同样的错误,我们将不胜感激。
提前致谢。
【问题讨论】:
标签: vba ms-project