Conditional Format - using VBA

N

Newbie

We have written the simple VBA codes to change the color of the text.
However, when I executed with Macros, I received an error.

"Run time error '1100'
The Method is not available in this situation"


Background -> We downloaded the file and associated that field,
"Type"
with the "Text10" in Microsoft Project Professional 2007. There are
values in the "Type" field, which are "Management" and "Employee". We
would like to differentiate the colors.


(We have already used "Marked tasks".)


The codes that we wrote were:
-------------------
Public Sub Change_Color()


Dim tskT As Task


For Each tskT In ActiveProject.Tasks


Select Case tskT.Text10


Case "Management"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjRed


Case "Employee"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlue


End Select


Next tskT


End Sub


------------------------


When we debugged this macros, it highlighted the line that has the
font color. We changed the number to 1 or 2, it still did not work.


Requests:


1. Can anyone assist in correcting this code?
2. In order to enhance, how can I add the background color? Will the
back color command work?


I do appreciate your response. I thought that we have almost nailed
this down. Thanks.
 
J

Jan De Messemaeker

Hi,

I just tried your code and it worked to perfection.
I don't understand, especially when it is that line; I would expect you to
be stuck on a blank line - one should NEVER use for each task without
immediately testing If not TskT is Nothing then!
But that would stop on the select case line

You may send me the file if you wish, I can have a closer look
jandemesATprom-ade.be

Greetings

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
J

John

Newbie said:
We have written the simple VBA codes to change the color of the text.
However, when I executed with Macros, I received an error.

"Run time error '1100'
The Method is not available in this situation"


Background -> We downloaded the file and associated that field,
"Type"
with the "Text10" in Microsoft Project Professional 2007. There are
values in the "Type" field, which are "Management" and "Employee". We
would like to differentiate the colors.


(We have already used "Marked tasks".)


The codes that we wrote were:
-------------------
Public Sub Change_Color()


Dim tskT As Task


For Each tskT In ActiveProject.Tasks


Select Case tskT.Text10


Case "Management"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjRed


Case "Employee"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlue


End Select


Next tskT


End Sub


------------------------


When we debugged this macros, it highlighted the line that has the
font color. We changed the number to 1 or 2, it still did not work.


Requests:


1. Can anyone assist in correcting this code?
2. In order to enhance, how can I add the background color? Will the
back color command work?


I do appreciate your response. I thought that we have almost nailed
this down. Thanks.

Newbie,
If I may chime in, I too ran your code and it works fine. My guess is
that you are missing an object library reference. Open the code window
and go to Tools/References. As a minimum you should have:
Visual Basic for Applications
Microsoft Project 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Object Library

If you are missing one of those, find it in the list of references and
check it. Then save your Global and try your code again.

By the way, just a suggestion. You might want to add Option Compare Text
to your code. That way, it will recognize "management" and "employee"
even if they are not capitalized (i.e. case insensitive).

John
Project MVP
 
J

Jan De Messemaeker

Hello,

You cannot use font on group summaries; your view was grouped (and sorted!)
That also has the consquence that your selection will not point to the task
with that id since it is on a row line with a different id. (in other words
row number is different from task id)

Here's better:

Public Sub Change_Color()
ViewApply "Gantt Chart"
GroupApply "No Group"
FilterApply "All Tasks"
Sort key1:="ID"
'All of this will ensure tasks are in ID order and the selection points to
the righyt task
Dim tskT As Task
For Each tskT In ActiveProject.Tasks
If Not tskT Is Nothing Then

Select Case tskT.Text10
Case "Management"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjRed
Case "Employee"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlue
End Select
End If
Next tskT
End Sub

Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 

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