0

I've copied some VBA code from learn.microsoft.com to get a better understanding of how the summary task object works in MS project. However am receiving runtime 91 errors on the original code, please see below:

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

The runtime 91 error identifies this line:

If tsk.Summary Then".

After googling possible causes I installed/reinstalled MS project.

Any help on what could be causing this would be greatly appreciated as I've noticed the same error on another learn.microsoft.com VBA script.

Thanks in advance.

1 Answer 1

2

Check tsk for not being Nothing, like this:

 For Each tsk In ActiveProject.Tasks
     If Not tsk is Nothing Then
          If tsk.Summary Then
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.