Hello Pascal,
Did you not get the following response?
Start of the earlier posting:
Newsgroups: microsoft.public.office.developer.com.add_ins
From: (e-mail address removed) (Chris Jensen [MSFT])
Date: Fri, 23 Jan 2004 22:36:18 GMT
Subject: RE: Resource creation in a Addin of MS Project
Hello Pascal,
You'll need to change the contents of the "Name" field of the row.
Here is an idea of the code to do that
private MSProject.Application oApp;
private MSProject.Project oProj;
private Missing oMissing = Missing.Value;
. . .
private void OpenProject_Click(object sender, System.EventArgs e)
{
oApp = new MSProject.Application();
oApp.FileOpen("C:\\ProjectA.mpp",
false, // ReadOnly
oMissing, // merge
oMissing, // taskinformation
oMissing, // Table
oMissing, // Sheet
oMissing, // noAuto
oMissing, // userID
oMissing, // DatabasePassword
oMissing, // FormatID
oMissing, // map
0, // OpenPool
oMissing, // password
oMissing, // writeResPassword
oMissing, // ignoreReadOnlyRecommended
oMissing); // XMLName - 16 arguments
oApp.Visible = true;
oProj = oApp.ActiveProject;
object oView = "Resource &Sheet";
object oRes = "Nuclear Physicist";
object oRes1;
object oRes2 = "Brain Surgeon";
int idx = 1;
oApp.ViewApply(oView,oMissing,oMissing);
oProj.Resources.Add(oRes,(object)idx); //(object)
idx);
oApp.SelectResourceField(0, "Name",oMissing,oMissing, oMissing,
oMissing,oMissing);
oRes1 = oApp.ActiveCell.Text;
MessageBox.Show("Name already set = " + oRes1);
idx = idx + 1;
oProj.Resources.Add(oRes2,(object)idx);
oApp.SelectResourceField(1, "Name",oMissing,oMissing, oMissing,
oMissing,oMissing);
oRes1 = oApp.ActiveCell.Text;
MessageBox.Show("Second Name set = " + oRes1);
oApp.SelectResourceField(0,"Cost per
Use",oMissing,oMissing,oMissing,oMissing,oMissing);
oApp.SetResourceField("Cost per
Use","$145.00",oMissing,oMissing,oMissing,oMissing);
oRes1 = oApp.ActiveCell.Text;
MessageBox.Show("Resource value = " + oRes1);
}
End of earlier posting.
When you add a resource you provide one argument - i.e. the name. All the
other fields are set to default values, which will be $0.00 or 0 or blank.
You have to supply values for each of the other fields. The example above
sets the value of the "Cost per Use" field. You can learn the exact field
names by viewing the Resource sheet, then holding your mouse over the
column headings. The column heading for Cost per Use is shown as Cost/Use.
That latter will cause the code to show an error, because Cost/Use isn't a
field name. When you hold your mouse over the gray column heading that
says Cost/Use you'll see a tool-tip that says Cost per Use. You can get the
names of each of the other fields the same way. You may not need to supply
values for each and every field, but for those you wish to change you'll
need code similar to that in the example above.
When you add a second resource, don't use the original name, but rather,
supply a new name for the new resource. In the example above the first
resource was Nuclear Physicist. The next resource was named Brain Surgeon.
You don't need to create a second Nuclear Physicist resource, then change
its name (although you can do that if you wish).
I hope this gives you the information you need.
Chris Jensen (Microsoft Corporation)