Work anywhere from any device with Microsoft 365

Upgrade to Microsoft 365 to work anywhere with the latest features and updates.

Upgrade now

Runtime error '91'


From a Cumulative project with 200+ project im getting a runtime error with following vba code:

Sub Macro1()
' Makro Macro1
Dim i As Integer
Dim subproj As MSProject.Subproject

    For Each subproj In ActiveProject.Subprojects
        i = i + 1
        MsgBox subproj.SourceProject.Name & " number " & i & " index " & subproj.Index

End Sub

Im getting following error at projectindex 25

Runtime Error '91'

Object variable or with block variable not set

What am i doing wrong? this only for testing, the goal is to print the subprojects with unfinished tasks






A suggestion. Instead of using the MsgBox Function, try the following syntax,

Debug.Print sp.SourceProject.ProjectStart

Debug.Print sp.SourceProject.ProjectFinish

That will save a lot of hitting the "OK" button each time the message pops up. To view the results with this modification, go to View/Immediate Window.

Just curious, did your test with 39 subprojects include the 25th subproject?


1 person was helped by this reply


Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.


Question Info

Last updated June 27, 2019 Views 1,787 Applies to: