FileSaveAs to MDB format

P

Phillip D

All I'm trying to do is use automation/c# to open an existing mpp file and
save it in mdb format. The code below opens the mpp file just fine, and the
call to FileSaveAs returns true - however it doesn't actually save the save
in mdb/access format. I must be missing something very obvious, but what?

private void SaveAsMdb()
{
Object oTrue = true;
Object oFalse = false;
string strProject = @"C:\Test\Project.mpp";
string strMdb = @"C:\Test\Access.mdb";

MSProject.ApplicationClass projectApp = new
MSProject.ApplicationClass();
projectApp.Visible = true;

projectApp.FileOpen(strProject, Missing.Value, oFalse,
Missing.Value, Missing.Value,
Missing.Value, oTrue, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value,
Microsoft.Office.Interop.MSProject.PjPoolOpen.pjDoNotOpenPool,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value);

projectApp.FileSaveAs(strMdb,
Microsoft.Office.Interop.MSProject.PjFileFormat.pjMPP,
Missing.Value, Missing.Value, oTrue,
Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, "MSProject.mdb",
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value);


projectApp.Quit(Microsoft.Office.Interop.MSProject.PjSaveType.pjDoNotSave);
}
 
C

Calvin

I guess it is because you use

Microsoft.Office.Interop.MSProject.PjFileFormat.pjMPP
 
P

Phillip D

I agree that it looks odd, but according to the documentation that I found,
that parameter is only used if the FormatID parameter is blank. And in my
case (I know, it's hard to read), the FormatID is set to "MSProject.mdb".
Again, "MSProject.mdb" looks odd as well, but the documentation claims that's
the correct FormatID if you want to save in Access format.

Having said that, my code doesn't work - so I must have misinterpreted
something.

Thanks,
Phil
 
R

Rod Gill

Try recording macros in VBA then your problem is only converting working VBA
to C#. Using VB for automating Office applications is also much quicker and
easier than using C# as VB has optional and named parameters and better
intellisense. Together it produces much more readable code that is quicker
to develop and test.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
C

Calvin

Yes try record the marco first. I can see that's the parameter for access

Filename = "<C:\Project1.mdb>\Project1"
FormatID = "MSProject.MDB8"
 
P

Phillip D

Thanks (to Calvin and Rob).

I recorded a macro, saw something similar to Calvin's response and was
excited. But, when I updated my C# code - no luck. Frustrated, I took Rod's
advice (as a test) and coded up a small VB.net app to perform the FileSaveAs.
Well, the VB app worked right away (and I love the named parameters, why
doesn't C# have those?).

Here's the working function (in VB):

Private Sub SaveAs()
Dim projectApp As MSProject.ApplicationClass = New
MSProject.ApplicationClass()
Dim strProjName As String
Dim strFormatID As String
Dim strAccessName As String

strProjName = "C:\Project.mpp"
strAccessName = "<C:\Access.mdb>\Project.mpp"
strFormatID = "MSProject.MDB8"

projectApp.Visible = False
projectApp.FileOpen(Name:=strProjName)

projectApp.FileSaveAs(Name:=strAccessName, FormatID:=strFormatID)

projectApp.Quit(MSProject.PjSaveType.pjDoNotSave)
End Sub

Thanks again,
Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top