I have an excel Macro which is supposed to open up MS Project and make a change to some custom fields and then close it again. Excel and Project are both version 2010, and the project is stored on MS Project Server 2010.
When I open MS Project manually and then detect it with VBA, everything works. But when I use VBA to open a new instance of Project (because I haven't manually opened MS Project), it throws an error:
Here are the two versions of the code:
Sub open_project_with_error()
Dim projapp As MSProject.Application, prj As Project
Set projapp = New MSProject.Application
projapp.FileOpenEx Name:="<>\Name of my project", ReadOnly:=False
Set prj = Projects("Name of my project")
' Do more things...
End Sub
Sub open_project_without_error()
' Manually open MS Project application before running this VBA
Dim projapp As MSProject.Application, prj As Project
Set projapp = GetObject(, "MSProject.Application")
projapp.FileOpenEx Name:="<>\Name of my project", ReadOnly:=False
Set prj = Projects("Name of my project")
' Do more things...
End Sub
Naturally, I expected that the problem was with the statement New MSProject.Application. However, this sub works perfectly, as expected:
Sub open_project_and_display_about()
Dim projapp As MSProject.Application, prj As Project
Set projapp = New MSProject.Application
Debug.Print projapp.About()
End Sub
Which means that the error is only triggered by the combination of New MSProject.Application and New MSProject.Application.
Any way to resolve it?

Here are some suggestions to try:
projapp.Visible = Trueto help debug issues.Dim prj as MSProject.ProjectandSet prj = projapp.Projects(....FWIW I am not able to replicate this issue with project pro 2013 opening files from project server.