How to create a group in VBA?

L

luvgreen

I tried to record the process of creating a new group, however, no code was
recorded. Is there any code sample to create a group?

Also, how can I evalutate if a user-define group is existing in code?

Thanks much!!!
 
J

Jan De Messemaeker

Hi,

Never grouped in code but a rapid look at the help gave this:
------------------------------------------
TaskGroupList Property


Returns a List object representing the task groups in the active project.
Read-only.
--------------------------------------------

Looking again I found
---------------------------------------------
TaskGroups Collection Object







Represents all the task-based group definitions.

Using the TaskGroups Collection

Use the TaskGroups property to return a TaskGroups collection. The following
example lists the names of all the task groups in the active project.

Dim TG As Group
Dim Groups As String

For Each TG in ActiveProject.TaskGroups
Groups = Groups & TG.Name & vbCrLf
Next TG

MsgBox Groups
Use the Add method to add a Group object to the TaskGroups collection. The
following example creates a new group that groups tasks by whether they are
overallocated or not and then modifies the criterion so that overallocated
tasks are sorted in descending order.

ActiveProject.TaskGroups.Add "Overallocated Tasks", "Overallocated"
ActiveProject.TaskGroups("Overallocated Tasks").GroupCriteria(1).Ascending =
False
 
L

luvgreen

Thank you so very much!! This is very helpful.

Jan De Messemaeker said:
Hi,

Never grouped in code but a rapid look at the help gave this:
------------------------------------------
TaskGroupList Property


Returns a List object representing the task groups in the active project.
Read-only.
--------------------------------------------

Looking again I found
---------------------------------------------
TaskGroups Collection Object







Represents all the task-based group definitions.

Using the TaskGroups Collection

Use the TaskGroups property to return a TaskGroups collection. The following
example lists the names of all the task groups in the active project.

Dim TG As Group
Dim Groups As String

For Each TG in ActiveProject.TaskGroups
Groups = Groups & TG.Name & vbCrLf
Next TG

MsgBox Groups
Use the Add method to add a Group object to the TaskGroups collection. The
following example creates a new group that groups tasks by whether they are
overallocated or not and then modifies the criterion so that overallocated
tasks are sorted in descending order.

ActiveProject.TaskGroups.Add "Overallocated Tasks", "Overallocated"
ActiveProject.TaskGroups("Overallocated Tasks").GroupCriteria(1).Ascending =
False
------------------------------------------------

In VBE, click the Object Browser Icon, type "Group"... that gives al there
is to know





--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/index.htm
32-495-300 620
 

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