Interop.MSProject FileSaveAs

  • Thread starter Thread starter Herb
  • Start date Start date
H

Herb

In trying to write VB.Net code to control MSProject 2003 it was recommended
that I record a macro in MSProject and transfer the code to VB.Net. When
recording the FileSaveAs (to the project server) I get the following:

FileSaveAs(Name:="<>\MyProject.Published", UserID:="", DatabasePassWord:="",
FormatID:="")

However, this gives me the "useful" error message "An unexpected error
occurred with the method." when applied to my application in the following
way:

Dim prj As New Microsoft.Office.Interop.MSProject.Application

With prj
.FileOpen("c:\prjTemplate.mpp")
.ActiveProject.Name = "DOG"
.ActiveProject.Comments = "CAT"
.FileSaveAs(Name:="<>\MyProject.Published", UserID:="",
DatabasePassWord:="", FormatID:="")
.FileClose()
End With

Any help would be appreciated.
 
Hello stullhe104

The error happens for lack of the credential information. When you record
macros, Project does not record the user id and password information for
sake of security. Thus, you see the UserID and DatabasePassWord parameters
be "" in the code. We would need to manually specify their values.

In addition, you would need to make sure that your Project is not working
offline, and the user logged on has the proper permission. Otherwise, an
error message "You do not have sufficient permissions to add new projects to
Project Server" will be popped up. Project allows us to choose the account
when it starts up.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Thanks for the reply. When I provide my Windows Auth userid and password I
get the same error.

.FileSaveAs(Name:="<>\MyProject.Published", UserID:="DOMAIN\USERID",
DatabasePassWord:="mypasword", FormatID:="")
 
Hello stullhe104,

The error this time is caused by the possibility that the MSProject instance
is working offline (see the second point in my last reply). My colleague Ji
Zhou [MSFT] and I are searching for the possible solutions of automating
Project to connect to the Project server. We will get back to you as soon as
possible.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Thanks. I await your reply.

--
stullhe104


Jialiang Ge said:
Hello stullhe104,

The error this time is caused by the possibility that the MSProject instance
is working offline (see the second point in my last reply). My colleague Ji
Zhou [MSFT] and I are searching for the possible solutions of automating
Project to connect to the Project server. We will get back to you as soon as
possible.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================


Herb said:
Thanks for the reply. When I provide my Windows Auth userid and password I
get the same error.

.FileSaveAs(Name:="<>\MyProject.Published", UserID:="DOMAIN\USERID",
DatabasePassWord:="mypasword", FormatID:="")
 
Hi,

How is Project initiated? If your code does this, then how have you logged
onto Project Server?

If I wanted to start project from Excel VBA I would use:

Sub StartProject()
'Requires Reference to Microsoft Project
Dim projApp As MSProject.Application
On Error Resume Next
'Uses Windows Authentication as no username or password parameters added
Shell "winproj.exe /s http://ProjectServerName/ProjectServer/"
Do Until Not (projApp Is Nothing)
DoEvents
Set projApp = GetObject(, "MSProject.Application")
Loop
Debug.Print projApp.Name
Debug.Print projApp.Profiles. _
ActiveProfile.ConnectionState
projApp.Quit
Set projApp = Nothing
End Sub

This code won't need much change to work in VB

--



Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
Hello Herb,

This is Ji Zhou [MSFT] and I will be working on this issue with you when my
colleague Jialiang Ge is on leave.

After some research on my side about this issue, I find out the error
results from we are running on the local account “My Computer†instead of an
Project Server account. Thus, the key point is we need to force project to
start using a server account. I did not find any way to programmatically
achieve that. Currently, my workaround is same as Rod’s. I am giving it in
VB.NET version. We need to call Process.Start to start the project
application and then get the application object by Marshal.GetActiveObject()
method. The following is my code which works fine in my side:

Sub Main()
On Error Resume Next
Process.Start("C:\Program Files\Microsoft Office\Office11\Winproj.exe")
Console.WriteLine("Waiting for the Project registered in ROT:")
Threading.Thread.Sleep(5000)

Dim app As MSProject.Application = Nothing

Do Until Not (app Is Nothing)
app = Marshal.GetActiveObject("MSProject.Application")
Loop

Console.WriteLine("The active profile information is:")
Console.WriteLine(app.Profiles.ActiveProfile.Name)

app.FileSaveAs(Name:="<>\mytest.Published")
Console.WriteLine("Saved to the Project Server 2003 successfully")
End Sub

As we see, we make the calling thread sleep for 5 seconds before we get the
active project application instance. The reason for doing this is the Office
application is not registered in the running object table as soon as it
starts. So, if we call Marshal.GetActiveObject immediately after calling
Process.Start, an error will be thrown to say that cannot find the active
application instance.

Another thing to mention is that I did not pass parameters into
Process.Start() function to specify the server and account information
because I set my server account as default and checked the Automatically
detect connection state option, in the Project Server Accounts dialog. To
show the dialog, we need to click Menu->Enterprise Option->Microsoft Office
Project Server Accounts

Please let me know if the workaround works for you or not. And if you have
any future questions or concerns, please feel free to let me know, I will
try my best to help!


Best regards,
Ji Zhou ([email protected], remove ‘online.’)
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.


Herb said:
Thanks. I await your reply.

--
stullhe104


Jialiang Ge said:
Hello stullhe104,

The error this time is caused by the possibility that the MSProject
instance
is working offline (see the second point in my last reply). My colleague
Ji
Zhou [MSFT] and I are searching for the possible solutions of automating
Project to connect to the Project server. We will get back to you as soon
as
possible.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================


Herb said:
Thanks for the reply. When I provide my Windows Auth userid and
password I
get the same error.

.FileSaveAs(Name:="<>\MyProject.Published", UserID:="DOMAIN\USERID",
DatabasePassWord:="mypasword", FormatID:="")

--
stullhe104


:

Hello stullhe104

The error happens for lack of the credential information. When you
record
macros, Project does not record the user id and password information
for
sake of security. Thus, you see the UserID and DatabasePassWord
parameters
be "" in the code. We would need to manually specify their values.

In addition, you would need to make sure that your Project is not
working
offline, and the user logged on has the proper permission. Otherwise,
an
error message "You do not have sufficient permissions to add new
projects
to
Project Server" will be popped up. Project allows us to choose the
account
when it starts up.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments
and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of
service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================


In trying to write VB.Net code to control MSProject 2003 it was
recommended
that I record a macro in MSProject and transfer the code to VB.Net.
When
recording the FileSaveAs (to the project server) I get the
following:

FileSaveAs(Name:="<>\MyProject.Published", UserID:="",
DatabasePassWord:="",
FormatID:="")

However, this gives me the "useful" error message "An unexpected
error
occurred with the method." when applied to my application in the
following
way:

Dim prj As New Microsoft.Office.Interop.MSProject.Application

With prj
.FileOpen("c:\prjTemplate.mpp")
.ActiveProject.Name = "DOG"
.ActiveProject.Comments = "CAT"
.FileSaveAs(Name:="<>\MyProject.Published", UserID:="",
DatabasePassWord:="", FormatID:="")
.FileClose()
End With

Any help would be appreciated.
 
Thanks for the reply. I will investigate this today and get back to you.
--
stullhe104


"Ji Zhou [MSFT]" said:
Hello Herb,

This is Ji Zhou [MSFT] and I will be working on this issue with you when my
colleague Jialiang Ge is on leave.

After some research on my side about this issue, I find out the error
results from we are running on the local account “My Computer†instead of an
Project Server account. Thus, the key point is we need to force project to
start using a server account. I did not find any way to programmatically
achieve that. Currently, my workaround is same as Rod’s. I am giving it in
VB.NET version. We need to call Process.Start to start the project
application and then get the application object by Marshal.GetActiveObject()
method. The following is my code which works fine in my side:

Sub Main()
On Error Resume Next
Process.Start("C:\Program Files\Microsoft Office\Office11\Winproj.exe")
Console.WriteLine("Waiting for the Project registered in ROT:")
Threading.Thread.Sleep(5000)

Dim app As MSProject.Application = Nothing

Do Until Not (app Is Nothing)
app = Marshal.GetActiveObject("MSProject.Application")
Loop

Console.WriteLine("The active profile information is:")
Console.WriteLine(app.Profiles.ActiveProfile.Name)

app.FileSaveAs(Name:="<>\mytest.Published")
Console.WriteLine("Saved to the Project Server 2003 successfully")
End Sub

As we see, we make the calling thread sleep for 5 seconds before we get the
active project application instance. The reason for doing this is the Office
application is not registered in the running object table as soon as it
starts. So, if we call Marshal.GetActiveObject immediately after calling
Process.Start, an error will be thrown to say that cannot find the active
application instance.

Another thing to mention is that I did not pass parameters into
Process.Start() function to specify the server and account information
because I set my server account as default and checked the Automatically
detect connection state option, in the Project Server Accounts dialog. To
show the dialog, we need to click Menu->Enterprise Option->Microsoft Office
Project Server Accounts

Please let me know if the workaround works for you or not. And if you have
any future questions or concerns, please feel free to let me know, I will
try my best to help!


Best regards,
Ji Zhou ([email protected], remove ‘online.’)
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.


Herb said:
Thanks. I await your reply.

--
stullhe104


Jialiang Ge said:
Hello stullhe104,

The error this time is caused by the possibility that the MSProject
instance
is working offline (see the second point in my last reply). My colleague
Ji
Zhou [MSFT] and I are searching for the possible solutions of automating
Project to connect to the Project server. We will get back to you as soon
as
possible.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================


Thanks for the reply. When I provide my Windows Auth userid and
password I
get the same error.

.FileSaveAs(Name:="<>\MyProject.Published", UserID:="DOMAIN\USERID",
DatabasePassWord:="mypasword", FormatID:="")

--
stullhe104


:

Hello stullhe104

The error happens for lack of the credential information. When you
record
macros, Project does not record the user id and password information
for
sake of security. Thus, you see the UserID and DatabasePassWord
parameters
be "" in the code. We would need to manually specify their values.

In addition, you would need to make sure that your Project is not
working
offline, and the user logged on has the proper permission. Otherwise,
an
error message "You do not have sufficient permissions to add new
projects
to
Project Server" will be popped up. Project allows us to choose the
account
when it starts up.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments
and
suggestions about how we can improve the support we provide to you.
Please
feel free to let my manager know what you think of the level of
service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no
rights.
=================================================


In trying to write VB.Net code to control MSProject 2003 it was
recommended
that I record a macro in MSProject and transfer the code to VB.Net.
When
recording the FileSaveAs (to the project server) I get the
following:

FileSaveAs(Name:="<>\MyProject.Published", UserID:="",
DatabasePassWord:="",
FormatID:="")

However, this gives me the "useful" error message "An unexpected
error
occurred with the method." when applied to my application in the
following
way:

Dim prj As New Microsoft.Office.Interop.MSProject.Application

With prj
.FileOpen("c:\prjTemplate.mpp")
.ActiveProject.Name = "DOG"
.ActiveProject.Comments = "CAT"
.FileSaveAs(Name:="<>\MyProject.Published", UserID:="",
DatabasePassWord:="", FormatID:="")
.FileClose()
End With

Any help would be appreciated.
 
Hello Herb,

I am writing to check the status of the issue on your side. Could you
please let me know if the suggestion works for you or not? If you have any
questions or concerns, please feel free to let me know. I will be more than
happy to be of assistance.

Have a great day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
Thanks for your concern.

I am just getting back to this issue today. I will try to respond again
tomorrow with a result.
 
Yes, this appears to have worked!

I will have to deal with the possibility that another winproj.exe is open,
but that should be cake compared to this.

Thanks,
 
Back
Top