GanttBarFormat questions

E

Earl Lewis

Anyone have any idea why this code causes the "Format Bar" window to open for each task? According to the help the window should only open if GanttBarFormat is called with no arguments.

Just to be clear - I do NOT want the format window to open for each iteration - it needs to happen 'under the covers'.

Sub AddCostToGantt()
Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, LeftText:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, LeftText:=Null
End If
Next
End Sub

Thanks for any ideas you might have. Also, sorry if this is a double-post. My newsreader seems to be misbehaving today - or is it just me?

Earl
 
J

JackD

Earl,

What you are proposing to do is the absolute wrong way to do this.
The easy way to do it is to go to the format menu, select barstyles,
find the summary task bar and set the left text on it to be Cost1. That way
every summary bar will have that text and if a task is promoted to summary
then it will have that text as well - and of course the opposite when a
summary task is demoted.

If you need to do this with code, turn on the macro recorder and do what I
just said, then stop the recorder.

-Jack

Earl Lewis said:
Anyone have any idea why this code causes the "Format Bar" window to open
for each task? According to the help the window should only open if
GanttBarFormat is called with no arguments.
Just to be clear - I do NOT want the format window to open for each
iteration - it needs to happen 'under the covers'.
Sub AddCostToGantt()
Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, LeftText:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, LeftText:=Null
End If
Next
End Sub

Thanks for any ideas you might have. Also, sorry if this is a double-post.
My newsreader seems to be misbehaving today - or is it just me?
 
E

Earl Lewis

Jack,

Thanks for your post but your suggestion does not answer my question. The question I asked is, why does the call to the GanttBarFormat function open the dialog when it's not supposed to?? This is a simple question related to VBA coding - not how to navigate the Project Pro user interface. The bottom line is that the function call does not appear to be behaving like it's supposed to.

Anyone else have any ideas about this one?

Earl
Earl,

What you are proposing to do is the absolute wrong way to do this.
The easy way to do it is to go to the format menu, select barstyles,
find the summary task bar and set the left text on it to be Cost1. That way
every summary bar will have that text and if a task is promoted to summary
then it will have that text as well - and of course the opposite when a
summary task is demoted.

If you need to do this with code, turn on the macro recorder and do what I
just said, then stop the recorder.

-Jack

Earl Lewis said:
Anyone have any idea why this code causes the "Format Bar" window to open
for each task? According to the help the window should only open if
GanttBarFormat is called with no arguments.
Just to be clear - I do NOT want the format window to open for each
iteration - it needs to happen 'under the covers'.
Sub AddCostToGantt()
Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, LeftText:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, LeftText:=Null
End If
Next
End Sub

Thanks for any ideas you might have. Also, sorry if this is a double-post.
My newsreader seems to be misbehaving today - or is it just me?
 
J

JackD

Sometimes the most correct answer to questions about project is "don't do it
that way".

Unfortunately you can't use code to set it to null. Setting it to "" doesn't
work either.
If you must use code, the only workaround that comes to mind is to set it to
some unused text field.

All this is avoided if you use the format/barstyles menu command. Or perhaps
apply a predefined view from the enterprise global.mpt.

-Jack


Earl Lewis said:
Jack,

Thanks for your post but your suggestion does not answer my question. The
question I asked is, why does the call to the GanttBarFormat function open
the dialog when it's not supposed to?? This is a simple question related to
VBA coding - not how to navigate the Project Pro user interface. The bottom
line is that the function call does not appear to be behaving like it's
supposed to.
 
E

Earl Lewis

In case anyone is interested this is my solution to the problem I had. Although it still doesn't answer the question about why the dialog window opens when GanttBarFomat is called WITH arguments, which according to the M$ documentation it shouldn't.


Function ShowCostOnGantt(bShow As Boolean) As Boolean
If bShow Then
GanttBarStyleEdit Item:="Summary", LeftText:="Cost1"
Else
GanttBarStyleEdit Item:="Summary", LeftText:=""
End If
End Function

Then I just call the function like this to turn the cost on:

ShowCostOnGantt(True)

or this to turn it off:

ShowCostOnGantt(False)

Anyone have any idea why this code causes the "Format Bar" window to open for each task? According to the help the window should only open if GanttBarFormat is called with no arguments.

Just to be clear - I do NOT want the format window to open for each iteration - it needs to happen 'under the covers'.

Sub AddCostToGantt()
Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, LeftText:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, LeftText:=Null
End If
Next
End Sub

Thanks for any ideas you might have. Also, sorry if this is a double-post. My newsreader seems to be misbehaving today - or is it just me?

Earl
 
J

JackD

The dialog window opens because you supplied an invalid argument. Null is
not a valid argument. "" is not valid either.
Does that answer your question?

-Jack


Earl Lewis said:
In case anyone is interested this is my solution to the problem I had.
Although it still doesn't answer the question about why the dialog window
opens when GanttBarFomat is called WITH arguments, which according to the M$
documentation it shouldn't.
Function ShowCostOnGantt(bShow As Boolean) As Boolean
If bShow Then
GanttBarStyleEdit Item:="Summary", LeftText:="Cost1"
Else
GanttBarStyleEdit Item:="Summary", LeftText:=""
End If
End Function

Then I just call the function like this to turn the cost on:

ShowCostOnGantt(True)

or this to turn it off:

ShowCostOnGantt(False)


Anyone have any idea why this code causes the "Format Bar" window to open
for each task? According to the help the window should only open if
GanttBarFormat is called with no arguments.
Just to be clear - I do NOT want the format window to open for each
iteration - it needs to happen 'under the covers'.
Sub AddCostToGantt()
Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, LeftText:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, LeftText:=Null
End If
Next
End Sub

Thanks for any ideas you might have. Also, sorry if this is a double-post.
My newsreader seems to be misbehaving today - or is it just me?
 
E

Earl Lewis

Here's a version that loops through the tasks and makes the change I want.

Sub TestGanttFormat()

Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, GanttStyle:=5, lefttext:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, GanttStyle:=5, Reset:=True
End If
Next

End Sub

The dialog window opens because you supplied an invalid argument. Null is
not a valid argument. "" is not valid either.
Does that answer your question?

-Jack


Earl Lewis said:
In case anyone is interested this is my solution to the problem I had.
Although it still doesn't answer the question about why the dialog window
opens when GanttBarFomat is called WITH arguments, which according to the M$
documentation it shouldn't.
Function ShowCostOnGantt(bShow As Boolean) As Boolean
If bShow Then
GanttBarStyleEdit Item:="Summary", LeftText:="Cost1"
Else
GanttBarStyleEdit Item:="Summary", LeftText:=""
End If
End Function

Then I just call the function like this to turn the cost on:

ShowCostOnGantt(True)

or this to turn it off:

ShowCostOnGantt(False)


Anyone have any idea why this code causes the "Format Bar" window to open
for each task? According to the help the window should only open if
GanttBarFormat is called with no arguments.
Just to be clear - I do NOT want the format window to open for each
iteration - it needs to happen 'under the covers'.
Sub AddCostToGantt()
Dim myTask As Task

For Each myTask In ActiveProject.Tasks
If myTask.Summary Then
GanttBarFormat TaskID:=myTask.ID, LeftText:="Cost1"
Else
GanttBarFormat TaskID:=myTask.ID, LeftText:=Null
End If
Next
End Sub

Thanks for any ideas you might have. Also, sorry if this is a double-post.
My newsreader seems to be misbehaving today - or is it just me?
 
J

JackD

However, if you have the gantt barstyle set to something which has a
lefttext of Cost1, then the code would reset to that value, and in that
case, there would be no visible effect.

This is why I avoid individual formatting of bars. Setting them with a style
is easier and more reliable.

-Jack
 

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