Results 1 to 15 of 15
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Task ID's and VBA (Project 2000)

    Hi

    I have a macro which runs through all the tasks in a macro using thetask object and I am getting some incorrect which make no sense.
    there are 76 tasks which all have ID's number 1 to 76, as some of the tasks are copied in from another project the Unique ID number is all over the place. Now when cycle through the tasks using a "for each tskTasks1 In ActiveProject.Tasks" it does not appear to count correctly, eg if I say stop as task ID 63 it stops at task 57. All the tasks have been expanded.

    Anybody have any clues

    Regards

    Mike

  2. #2
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Task ID's and VBA (Project 2000)

    I am assuming that you set the following in your code:

    Dim tskTasks1 as task

    How did you set your counter to loop through your tasks?

    I would guess that you are looping through the project using something like;
    For Each tskTasks1 in ActiveProject.Tasks (as you stated in your post)

    You would then normally have a counter that would increment with each loop or task.

    Sounds as if you have a problem with the counter / loop. Check your code to determine when you are moving to the next task to ensure the counter is being increments.

    How are you telling the system to stop at task ID 63? Are you referencing ActiveProject.Tasks(ID) ??

    Any chance there are blank rows ?

    Just some ideas to think about as it is unclear exactly what you are trying to do.

    HTH
    Regards,

    Gary
    (It's been a while!)

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Task ID's and VBA (Project 2000)

    Are you adding or removing any tasks in the loop.

    If for example you had a loop that said...
    <font color=blue>for each tskTasks1 In ActiveProject.Tasks
    tskTasks1.Delete
    next</font color=blue>
    Then you would only delete half the tasks.

    StuartR

  4. #4
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Hi Stuart

    This is the code I am using, I am purely running through the tasks to colour them based on the WBS element/Outline level.

    OutlineShowAllTasks
    For Each tskpjTasks1 In ActiveProject.Tasks
    strpjText1 = tskpjTasks1.WBS
    strpjText2 = tskpjTasks1.Name
    If tskpjTasks1 Is Nothing Then
    SelectTaskField row:=1, Column:="Name", rowrelative:=True
    GoTo Next_Loop
    End If
    Call mdl_pjCount_Levels(strpjText1, intpjCnt1)
    If Not blnpjSkip Then
    blnpjSkip = True
    SelectTaskField row:=1, Column:="Name", rowrelative:=False
    Else
    SelectTaskField row:=1, Column:="Name", rowrelative:=True
    End If
    Select Case intpjCnt1
    Case 0
    Font Color:=pjGreen
    Case 1
    Font Color:=pjMaroon
    Case 2
    Font Color:=pjTeal
    Case 3
    Font Color:=pjNavy
    End Select
    Next_Loop:
    'Next tskpjTasks1

    There are blank lines which should get skipped, it works fine if you create the project from scratch but if you copy in tasks from another project then it has a problem and it appears to be related to the ID and Unique ID numbers, which is the part I cannot understand.

    Regards

    Mike

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Hi Gary

    Thanks for the info, I have sent a reply to Gary below, could you see that which saves me typing it again.

    Thanks

    Mike

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Task ID's and VBA (Project 2000)

    I must confess that I don't understand parts of your code, but I really don't like the use of GoTo and it isn't necessary here.
    Could you replace
    <font color=blue>GoTo Next_Loop
    End If</font color=blue>
    With
    <font color=blue>Else
    ' put the rest of your code up to the Next_Loop label here
    End If</font color=blue>

    It won't fix your problem but it will reduce the number of VBA programs that use Goto by 1 <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    StuartR

  7. #7
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Thanks Stuart, valid point................. consider it changed

    Regards

    Mike

  8. #8
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Task ID's and VBA (Project 2000)

    First,

    The following simplifies your code (Ignoring the call statement)

    Dim TSKPJTASKS1 As Task

    OutlineShowAllTasks
    For Each TSKPJTASKS1 In ActiveProject.Tasks

    If Not TSKPJTASKS1 Is Nothing Then

    'Call mdl_pjCount_Levels(strpjText1, intpjCnt1)
    SelectTaskField row:=1, Column:="Name", rowrelative:=True
    Select Case intpjCnt1
    Case 0
    Font Color:=pjGreen
    Case 1
    Font Color:=pjMaroon
    Case 2
    Font Color:=pjTeal
    Case 3
    Font Color:=pjNavy
    End Select
    Else
    SelectTaskField row:=1, Column:="Name", rowrelative:=False
    End If
    Next TSKPJTASKS1

    Now some questions.
    1. What is your call statement doing? You are passing the WBS field and what to the sub? What results do you get back?
    2. You indicate that you are reviewing the tasks based on the WBS and Outline level. I don't see where in your code you are comparing to the outline level.

    Perhaps you can tell us what you are trying to do so we can help. For example, are you trying to set all outline levels 1 to green, 2 to blue, 3 to green, etc? What does the WBS have to do with this?

    Just curious.
    Regards,

    Gary
    (It's been a while!)

  9. #9
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Hi Gary,

    The call statement just works out what levels there are in the WBS element, 1.4.2 will give 3 as a return value then the colour is selected by the case statement. We are formatting all projects in the organisation the same, so as you say 1 to green, 2 to blue, 3 to green, etc.

    I am not comparing the WBS and Outline elements, I am using the WBS element or I could use the Outline element to determine the level of indentation.

    The issue is that if I create a project from scratch the ID and Unique ID numbers are the same and the macro works file, all levels get coloured correctly everytime. When I import task from another project using cut and paste the ID's renumber correctly but the Unique ID numbers become mixed up as it takes the numbers from the pasted tasks. Then the macro stops working correctly, it stops at the first pasted task and then appears to go all over the place.

    I hope that helps.

    Regards

    Mike

  10. #10
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Task ID's and VBA (Project 2000)

    The only thing I can think of is to compare to the outline.level to set the colors.

    Let me know if this works.
    Regards,

    Gary
    (It's been a while!)

  11. #11
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Hi Gary,

    The issue is not the outline level and the actual font colour, it is related to the ID and Unique ID, if I have a new project and the ID's and Unique ID's are the same and sequential the macro works, including any blank lines. If I paste tasks from another project the ID and Unique ID become different then the macro does not work correctly, it usually sets different colours and stop short.

    Regards

    Mike

  12. #12
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Task ID's and VBA (Project 2000)

    I guess I am confused. Your subroutine is calculating the level number based on the WBS (i.e., 1.4.2 is 3) and the color set accordingly. It appears that your subroutine is creating the problem when using it to calculate the level number based on imported other projects, however, can't help you there as I can't see it.

    What I was trying to get to is that if you are coloring the tasks via the outline level number, why not use the outline level number already generated by Project? The outline level number should be correct no matter what project is copied into the original project.

    Good Luck.
    Regards,

    Gary
    (It's been a while!)

  13. #13
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Hi Gary,

    Thanks for your efforts, I have it now working, the things that I have learnt are, I did not release that the Outline Level NUMBER was there, (I did not look very well) and I had my code slightly out of alignment. I have removed the subroutine now, although that had no effect, I had my SelectTaskField statements slightly wrong. All fixed now.

    Thanks for sticking with me and making me keep looking.

    One question, is there any good books on MS Project Macros which show the commands and details on the 115 fields available etc. I have not been trained and I could do with a good reference guide.

    Regards

    Mike

  14. #14
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Task ID's and VBA (Project 2000)

    Glad I could help.

    In response to your question, I am sure there are many books out there on MS Project Macro's. I use the Special Edition using Project 2000, however, it is more specific on using the system with a small section on macros. ** As to the field names, the book contains a CD with the documentation on the MS Project Fields, Table Structure, etc., named Project 2000 Field Directory (which should be what you are looking for).

    You should also be able to download the Field Directory from the Microsoft Support Knowledge Base (I did this once for Project 98 but couldn't find the link to the files for 2000).

    - One last item,
    Could you please post your final code so others can see and benefit from it. (Including myself...) I would like to see what you did to solve your problem.

    Good Luck with your programming.
    Regards,

    Gary
    (It's been a while!)

  15. #15
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Task ID's and VBA (Project 2000)

    Hi Gary

    Thanks for the information, abellow is the final version of the code.

    blnpjskip=False

    For Each tskpjTasks1 In ActiveProject.Tasks

    If Not blnpjSkip Then
    blnpjSkip = True
    SelectTaskField row:=1, Column:="Name", rowrelative:=False
    Else
    SelectTaskField row:=1, Column:="Name", rowrelative:=True
    End If

    If tskpjTasks1 Is Nothing Then

    Else

    strpjText3 = tskpjTasks1.OutlineLevel

    Select Case Val(strpjText3)

    Case 1
    Font Color:=pjGreen

    Case 2
    Font Color:=pjMaroon

    Case 3
    Font Color:=pjTeal

    Case 4
    Font Color:=pjNavy

    End Select

    End If

    Next tskpjTasks1

    It is basically what we had started with, but I got so hung up with the ID and Unique ID I could not see the wood for the trees.

    Thanks again.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •