Determine Outline Level in Project using Visual Basic

W

Walter L. skinner

I have a visual basic routine to automatically increase row height in a
project 2003 file, if the entry(data) in the Name Field is too long to fit
current Name Field width. However, I need to know the Outline Level or the
number of spaces to the first alphabetical character in oder to determine if
the text needs wrapping. If there is some way to do this, I would appreciate
it.

Walt Skinner
 
G

Gérard Ducouret

Hello Walt,

Have you tried something like :
ActiveCell.Task.OutlineLevel

Gérard Ducouret
 
J

John

Walter L. skinner said:
I have a visual basic routine to automatically increase row height in a
project 2003 file, if the entry(data) in the Name Field is too long to fit
current Name Field width. However, I need to know the Outline Level or the
number of spaces to the first alphabetical character in oder to determine if
the text needs wrapping. If there is some way to do this, I would appreciate
it.

Walt Skinner

Walt,
Gerard's suggestion will certainly work if you are using foreground
processing. In your previous post we didn't explicitly discuss
foreground versus background processing, but background processing is
generally always the better approach - faster and more efficient.
Background processing simply means that the code is working directly
with Project objects regardless of which view is active. Foreground
processing operates by selecting objects in the current view. However,
some of Project's objects can only be operated on in foreground
processing (e.g. font characteristics).

A basic (no pun intended) VBA loop to cycle through all tasks in a file
is as follows. I have included the syntax for determining the Outline
Number.

For Each t in ActiveProject.Tasks
If Not t is Nothing Then
OL = t.OutlineNumber
[your code here to parse the task name info]
End If
Next t

Hope this helps.
John
Project MVP
 
W

Walter L. skinner

John:
I've got this thing working fairly well even though the proportional fonts
give me fits.
One more question if you would please. I need to figure out what table is
active so that I can get the field (NAME) length so that I can set my trigger
to wrap to a new line.
Name_Width = ActiveProject.TaskTables("Walts table
text1").TableFields(2).Width

This code will give the second entry in the table (Task name field)'s
length. However, I need to do it dynamically since I don't know what table is
active and what relative position in the table the "NAME" field is.

Any help will be appreciated.

John said:
Walter L. skinner said:
I have a visual basic routine to automatically increase row height in a
project 2003 file, if the entry(data) in the Name Field is too long to fit
current Name Field width. However, I need to know the Outline Level or the
number of spaces to the first alphabetical character in oder to determine if
the text needs wrapping. If there is some way to do this, I would appreciate
it.

Walt Skinner

Walt,
Gerard's suggestion will certainly work if you are using foreground
processing. In your previous post we didn't explicitly discuss
foreground versus background processing, but background processing is
generally always the better approach - faster and more efficient.
Background processing simply means that the code is working directly
with Project objects regardless of which view is active. Foreground
processing operates by selecting objects in the current view. However,
some of Project's objects can only be operated on in foreground
processing (e.g. font characteristics).

A basic (no pun intended) VBA loop to cycle through all tasks in a file
is as follows. I have included the syntax for determining the Outline
Number.

For Each t in ActiveProject.Tasks
If Not t is Nothing Then
OL = t.OutlineNumber
[your code here to parse the task name info]
End If
Next t

Hope this helps.
John
Project MVP
 
J

Jan De Messemaeker

Hi,

Activeproject.currenttable
HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
+32-495-300 620
Walter L. skinner said:
John:
I've got this thing working fairly well even though the proportional fonts
give me fits.
One more question if you would please. I need to figure out what table is
active so that I can get the field (NAME) length so that I can set my trigger
to wrap to a new line.
Name_Width = ActiveProject.TaskTables("Walts table
text1").TableFields(2).Width

This code will give the second entry in the table (Task name field)'s
length. However, I need to do it dynamically since I don't know what table is
active and what relative position in the table the "NAME" field is.

Any help will be appreciated.

John said:
Walter L. skinner said:
I have a visual basic routine to automatically increase row height in a
project 2003 file, if the entry(data) in the Name Field is too long to fit
current Name Field width. However, I need to know the Outline Level or the
number of spaces to the first alphabetical character in oder to determine if
the text needs wrapping. If there is some way to do this, I would appreciate
it.

Walt Skinner

Walt,
Gerard's suggestion will certainly work if you are using foreground
processing. In your previous post we didn't explicitly discuss
foreground versus background processing, but background processing is
generally always the better approach - faster and more efficient.
Background processing simply means that the code is working directly
with Project objects regardless of which view is active. Foreground
processing operates by selecting objects in the current view. However,
some of Project's objects can only be operated on in foreground
processing (e.g. font characteristics).

A basic (no pun intended) VBA loop to cycle through all tasks in a file
is as follows. I have included the syntax for determining the Outline
Number.

For Each t in ActiveProject.Tasks
If Not t is Nothing Then
OL = t.OutlineNumber
[your code here to parse the task name info]
End If
Next t

Hope this helps.
John
Project MVP
 
J

John

Walter L. skinner said:
John:
I've got this thing working fairly well even though the proportional fonts
give me fits.
One more question if you would please. I need to figure out what table is
active so that I can get the field (NAME) length so that I can set my trigger
to wrap to a new line.
Name_Width = ActiveProject.TaskTables("Walts table
text1").TableFields(2).Width

This code will give the second entry in the table (Task name field)'s
length. However, I need to do it dynamically since I don't know what table is
active and what relative position in the table the "NAME" field is.

Any help will be appreciated.

Walt,
Yes proportional fonts are a real pain when it comes to determining the
actual dimensional length of a text string. There obviously is a way to
do it (i.e. that's what the word wrap algorithms in applications must
do) but I haven't found a way to do it with VBA. For my needs I did some
trial and error testing and then settled on a value.

With regard to finding the Name field width, I played with some code and
this is what I came up with. There may be a more direct way, but in the
short time I spent, I couldn't find anything. Note: In Project 2003 VBA
there is an AutoWrap property for the TaskTables collection but I
couldn't get it to work even though it says it is read/write (all too
often, the VBA help file lies).
Note: this only works if the Name field hasn't been re-named.

Option Compare Text
Sub WidthFinder()
z = ActiveProject.CurrentTable
Set x = ActiveProject.TaskTables(z).TableFields
For Each f In x
If f.Title = "task name" Then
NameFldWidth = f.Width
Exit For
End If
Next f
End Sub

Hope this helps.
John
Project MVP
 

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