LtLeary said:
Thanks JackD,
I really appreciate the feedback.
Perhaps I should rephrase what I am trying to do!!
I am programatically adding new tasks to a project and want to change
the font of certain tasks.
To change the font color of the newly added task, the only way that I
can come up with is to set the focus to the Field (in this case the
Task Name) and then change the font.
The only way I know to set the focus to the field is with the Find
method.
Any other ideas to change the font color? It would be great to be able
to do it at the same time I am adding the task, setting the dates,
durations, etc.
Thanks
LT
LT,
Your more thorough explanation helps a lot. Most of the time VBA code is
much more efficient running in background mode where project objects are
referenced directly, usually in a loop. That's why Jack say he doesn't
work directly with cells, and neither do most experienced VBA
developers. However, you have found one of the few areas where
foreground processing is the only option. In Project, font
characteristics can only be set on an active cell (or group of cells).
It's one of those little aggravating quirks of Project VBA.
As Jack noted, the find method is one way to activate the desired cell
but there are other methods. For example at the same time you add the
new task, select it after it has been added and then change the font.
Here's an alternate way to select the new task (although it may not be
any better than using the Find method):
NewID = ActiveProject.Tasks([name of added task]).GetField(pjTaskID)
SelectTaskField Row:=NewID, Column:="name", RowRelative:=False
Keep in mind that the task ID will not necessarily be the row number.
For example, if the Project Summary Task is visible or if the view is
filtered, sorted or otherwise modified the above won't work.
Here's another idea. If the same font characteristics will be the same
on all the added tasks, go ahead and add all the new tasks. Then filter
for those tasks (use a temporary flag if desired) and select the
filtered set. It is then pretty easy to cycle through the selected set
and change the font. As a matter of fact, I did a similar thing in a
macro I wrote years ago. I kept track of the changed tasks in an array
and then cycled through the array to select field cells in groups of 10
so I could set the font. At that time the maximum number of field cells
that could be selected at once was 10, hence the limit. Maybe that value
has changed, I don't know.
Hope this helps.
John
Project MVP