• Task ID’s and VBA (Project 2000)

    Home » Forums » AskWoody support » Productivity software by function » Other MS apps » Task ID’s and VBA (Project 2000)

    Author
    Topic
    #376912

    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

    Viewing 1 reply thread
    Author
    Replies
    • #619563

      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

      • #619887

        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

    • #619847

      Are you adding or removing any tasks in the loop.

      If for example you had a loop that said…
      for each tskTasks1 In ActiveProject.Tasks
      tskTasks1.Delete
      next

      Then you would only delete half the tasks.

      StuartR

      • #619885

        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

        • #619892

          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
          GoTo Next_Loop
          End If

          With
          Else
          ‘ put the rest of your code up to the Next_Loop label here
          End If

          It won’t fix your problem but it will reduce the number of VBA programs that use Goto by 1 smile

          StuartR

          • #619900

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

            Regards

            Mike

        • #619971

          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.

          • #619987

            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

            • #620188

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

              Let me know if this works.

            • #620191

              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

            • #620271

              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.

            • #620359

              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

            • #620402

              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.

            • #620630

              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

    Viewing 1 reply thread
    Reply To: Task ID’s and VBA (Project 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: