any way to highlight every other row in a project.

C

ChuckB

Would like to highlight every other row in a project plan; is VBA code the
ansher
and, if so, can I see an example.

Thanks,

Chuck
 
J

John

ChuckB said:
Would like to highlight every other row in a project plan; is VBA code the
ansher
and, if so, can I see an example.

Thanks,

Chuck

Chuck,
Be advised that Project is not like Excel. The field cell background
cannot be colored. You can however "highlight" field cells, row data or
column data by changing the font characteristics. And yes, that can be
done easily with VBA. The following code will change the text of all
even ID tasks to blue.

Sub Even_row_highlight()
i = 1
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
If t.ID = 2 * i Then
SelectRow Row:=t.ID, rowrelative:=False
Font Color:=pjBlue
i = i + 1
End If
End If
Next t

Hope this helps.
John
Project MVP
 
C

ChuckB

John said:
Chuck,
Be advised that Project is not like Excel. The field cell background
cannot be colored. You can however "highlight" field cells, row data or
column data by changing the font characteristics. And yes, that can be
done easily with VBA. The following code will change the text of all
even ID tasks to blue.

Sub Even_row_highlight()
i = 1
For Each t In ActiveProject.Tasks
If Not t Is Nothing Then
If t.ID = 2 * i Then
SelectRow Row:=t.ID, rowrelative:=False
Font Color:=pjBlue
i = i + 1
End If
End If
Next t

Hope this helps.
John
Project MVP
I copied the code into my project and got an error messagte
"can't find project or library" when I ran the macro.

Thanks,

Chuck
 
J

John

ChuckB said:
"can't find project or library" when I ran the macro.

Thanks,

Chuck

Chuck,
Well at least you found the right post - that's part "A".

I will assume you know how to set up and run a macro. If not, I'll
provide instructions.

The error message you get sounds like a reference needs to be set for
the object library. From the VB Editor go to Tools/References. As a
minimum, the following references should be checked:
1. Visual Basic for Applications
2. Microsoft Project xx.x Object Library (xx.x is the version of Project
you have installed - 11.0 is for Project 2003)
3. If those aren't checked, find them and check them
4. If it still gives the error, then also add the following references:
a. OLE Automation
b. Microsoft Office xx.x Object Library
5. When all object references are checked, hit "ok"

If the code still fails to execute, tell me exactly how you copied the
code and how you are attempting to run it. It would also be helpful to
know which version of Project you are using although for this simple
macro, it shouldn't matter.

John
Project MVP
 
C

ChuckB

John said:
Chuck,
Well at least you found the right post - that's part "A".

I will assume you know how to set up and run a macro. If not, I'll
provide instructions.

The error message you get sounds like a reference needs to be set for
the object library. From the VB Editor go to Tools/References. As a
minimum, the following references should be checked:
1. Visual Basic for Applications
2. Microsoft Project xx.x Object Library (xx.x is the version of Project
you have installed - 11.0 is for Project 2003)
3. If those aren't checked, find them and check them
4. If it still gives the error, then also add the following references:
a. OLE Automation
b. Microsoft Office xx.x Object Library
5. When all object references are checked, hit "ok"

If the code still fails to execute, tell me exactly how you copied the
code and how you are attempting to run it. It would also be helpful to
know which version of Project you are using although for this simple
macro, it shouldn't matter.

John
Project MVP
John:

Thanks for all the help and patience; I followed your suggestions and it
worked perfectly; is it possible to substitute other font changes for the
color that is currently
in the code--e.g., Font bold ??

Once again, thanks.

Chuck
 
J

John

Thanks for all the help and patience; I followed your suggestions and it
worked perfectly; is it possible to substitute other font changes for the
color that is currently
in the code--e.g., Font bold ??

Once again, thanks.

Chuck

Chuck,
You're welcome.

To see all the options for the Font Method, open the VB Editor and hit
the "Object Browser"icon or select it from the View menu. When the
object browser appars, in the upper selection box on the far upper left,
select "MSProject". In the selection box immediately below it, type in
"font". Then hit the binocular icon. The Search Results will list
several "finds" with the first one already selected. Hit the question
mark (Help) icon. The complete VB syntax for the Font Method will appear.

Hope this helps.
John
Project MVP
 
C

ChuckB

John said:
Chuck,
You're welcome.

To see all the options for the Font Method, open the VB Editor and hit
the "Object Browser"icon or select it from the View menu. When the
object browser appars, in the upper selection box on the far upper left,
select "MSProject". In the selection box immediately below it, type in
"font". Then hit the binocular icon. The Search Results will list
several "finds" with the first one already selected. Hit the question
mark (Help) icon. The complete VB syntax for the Font Method will appear.

Hope this helps.
John
Project MVP
Thanks for all the help; I learned quite a bit about VB from this exercise.
 
R

Roy

John,
I have changed this script a little to color fonts based on the content of a
field. I put in a Msgbox to show me the ID and the field to insure it is
finding the correct rows. Problem is that I see the correct row ID, but it
does not color all of the correct rows. Some are changed, some are not and
some that do not have the value I want are colored. I can not find a
pattern. Here is the code:


Dim intcntr As Integer
Dim tskT As Task

For Each tskT In ActiveProject.Tasks
If Not tskT Is Nothing Then
If tskT.Text18 = "A1" Then
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlue
End If
End If
Next tskT

thanks in advance for your assistance....
 
J

Jan De Messemaeker

Hi,

Your rows must be in the exact ID sequence
Better add:
Outlineshowalltasks
filterapply "All Tasks"

Hope this helps,
 

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