Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to edit TimescaleStart of MS Project Using C#.net

I have a requirement to modify the ms project file (.mpp) using C#.net.

I have done with all the things, the only thing remaining is to modify the TimescaleStart date of MPP file using C#.net. I need to set the user defined date.

How can i do that?

Following is my code:

Microsoft.Office.Interop.MSProject.Application app = new Microsoft.Office.Interop.MSProject.Application();
app.DisplayAlerts = false;
app.AskToUpdateLinks = false;


app.FileOpenEx(
strFilePath + "test.mpp",
false,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
PjPoolOpen.pjPoolReadWrite, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Microsoft.Office.Interop.MSProject.Project pj = app.ActiveProject;

object objDate = dt.Date;
app.TimescaleStart =   objDate;

Got Error as

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

on Following line:

app.TimescaleStart =   objDate;
like image 809
Shaikh Farooque Avatar asked Jun 08 '13 11:06

Shaikh Farooque


2 Answers

Could it be that you're actually trying to change the project start date?

If that's the case, try using the "ProjectMove" method. reference here and here.

If you really really want to change TimescaleStart, it looks like you are out of luck.

like image 75
Scott Solmer Avatar answered Nov 19 '22 16:11

Scott Solmer


TimescaleStart is a read-only property which returns the date that the timescale starts in the current view.

If you want to scroll the view so that it starts at a certain date, find a task with a start date on or close to your target date, select it and invoke the GotoTaskDates method of the application object. For example:

 app.Find "Start", "is greater than or equal to", "1/1/2014", Type.Missing, Type.Missing, Type.Missing, Type.Missing
 app.GotoTaskDates

Update:

If you are using Project 2010 or later, you can also use this method:

app.PanZoomPanTo (objDate)
like image 21
Rachel Hettinger Avatar answered Nov 19 '22 16:11

Rachel Hettinger