Programmatically setting active cell

L

LtLeary

Has anyone found a way to set the active cell programmatically?

The only way that I have found is to use the "find" method, but was
hoping to find an easier way.

Any help would be appreciated.

Lt
 
L

LtLeary

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
 
J

John

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
 
L

LtLeary

Thanks John,
Leave it to me to do the "non-traditional" programming!

I appreciate the tips.

Lt
 
J

John

LtLeary said:
Thanks John,
Leave it to me to do the "non-traditional" programming!

I appreciate the tips.

Lt

Lt,
I wouldn't call it "non-traditional". If Jack, myself or someone else
needed to change font characteristics we would also have to resort to
foreground processing. I believe most of the guys think I do a lot of
"non-traditional" stuff with VBA and they are probably right, but you do
what you gotta to get the job done, right?

John
Project MVP
 
L

LtLeary

I hear ya John.

Today's VBA certainly beats the old days of WFWG and DDE to Project for
Windows (or even the batch file/QB/procomm+/paradox pal scripting paper
clip and bubble bum "apps" I used to have to write!)

I do believe that someday, MS is really going to get all the apps
talking even better together and we will be able to use the same
methods across all platforms to do the same thing (e.g. in excel it is
sheets(1).range("B1").fontcolor = "pick a colorl") A bit different in
Visio and Access but still not a "foreground" activity!!!

Once more, I appreciate the ideas and validation I hadn't totally lost
my mind!

Lt
 
J

John

LtLeary said:
I hear ya John.

Today's VBA certainly beats the old days of WFWG and DDE to Project for
Windows (or even the batch file/QB/procomm+/paradox pal scripting paper
clip and bubble bum "apps" I used to have to write!)

I do believe that someday, MS is really going to get all the apps
talking even better together and we will be able to use the same
methods across all platforms to do the same thing (e.g. in excel it is
sheets(1).range("B1").fontcolor = "pick a colorl") A bit different in
Visio and Access but still not a "foreground" activity!!!

Once more, I appreciate the ideas and validation I hadn't totally lost
my mind!

Lt

Lt,
I don't want to scare you but its the guys who answer posts that
probably lost their minds. No person in their right mind would sit here
day after day answering questions by pretending to understand Project.

:)
John
 

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