Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
other
informationbridge
office.intranets
office.misc
office.setup
office.xml
officeupdate
onenote
photodraw.discussion
powerpoint
producer
proj.standard&server
project
project.developer
project.pro_and_serve
project.server
project.vba
project2000
publisher
publisher.prepress
publisher.programming
publisher.webdesign
visio
visio.createshapes
visio.database.modeling
visio.dev.diagrams
visio.dev.shapesheet
visio.dev.vba
visio.dev.vc
visio.developer
visio.general
visio.installation
visio.printing
visio.software.modeling
visio.troubleshoot
  
 
date: 2 Jan 2006 12:15:00 -0800,    group: microsoft.public.project.vba        back       


Link last task   
I am trying to find the latest finish date for a group of tasks
assigned to a certain resource and then to link that task to another
one as a predecessor.

So for example say I had a task called "Example"
I want to scan through all tasks in a project plan that belong to
person "A", find the one that has the latest finish date, and then link
that task to "Example" as a predeccesor.

I am assuming I would structure it this way:

(1) In a for loop, loop through all active tasks in the project.
(2) If current task in loop has resource = "a" then assign variable
Finish to finish date of that task.
(3) If Finish is greater then Final_Finish variable assign Finish to
Final Finish and assign ID of task to Final_Finish_ID.
(4) Keep looping.
(5) Assign Final_Finish_ID to the Predeccesor field of task "Example"

Ideally I would like to do this for each resource in the project so I
am assuming that I would have the above loop inside of another loop
that goes through each resource in the project. The "Example" task
would actually be a task with the person's name.

Is the above the easiest way to accomplish what i am trying to achieve
or is there an easier way? I have never programmed Project VBA so it
might take me a little while to figure out the language.

- John
date: 2 Jan 2006 12:15:00 -0800   author:   JoJa15

Re: Link last task   
OK, I got it to work with the following code. Is there an easier and quicker 
way to do this?

Sub Last_Task_Link()

    'If project is empty, alert the user and end the macro
    If ActiveProject.Tasks.Count = 0 Then
        MsgBox MSG_NO_TASKS, Buttons:=vbCritical + R_TO_L, 
Title:=Application.Name
        End
    End If


Dim Temp As Long, Temp2 As Long
Dim R As Long, Names As String, FinishDate As Date, FinishID As String

For R = 1 To ActiveProject.Resources.Count
    FinishID = 0
    FinishDate = 0
    Names = ActiveProject.Resources(R).Name
    For Temp = 1 To ActiveProject.Tasks.Count
        If Not ActiveProject.Tasks(Temp) Is Nothing Then
            If StrComp(Names, ActiveProject.Tasks(Temp).ResourceNames, 1) = 
0 Then
                If DateValue(ActiveProject.Tasks(Temp).Finish) >= 
DateValue(FinishDate) Then
                    FinishDate = ActiveProject.Tasks(Temp).Finish
                    FinishID = ActiveProject.Tasks(Temp).ID
                End If
            End If
        End If
    Next Temp
    For Temp2 = 1 To ActiveProject.Tasks.Count
        If Not ActiveProject.Tasks(Temp2) Is Nothing Then
            If StrComp(Names, ActiveProject.Tasks(Temp2).Name, 1) = 0 Then
                If Not FinishID = 0 Then
                    ActiveProject.Tasks(Temp2).Predecessors = FinishID
                End If
            End If
        End If
    Next Temp2
Next R

End Sub

- John
date: Mon, 2 Jan 2006 17:47:29 -0600   author:   John john[nospam]terminalreality.com

Re: Link last task   
Hi John,

Next time, please try posting on the developer newsgroup as this one's 
closing down.  Please see FAQ Item: 24. Project Newsgroups.   FAQs, 
companion products and other useful Project information can be seen at this 
web address: http://project.mvps.org/faqs.htm

Mike Glen
Project MVP


 John wrote:
> OK, I got it to work with the following code. Is there an easier and
> quicker way to do this?
>
> Sub Last_Task_Link()
>
>    'If project is empty, alert the user and end the macro
>    If ActiveProject.Tasks.Count = 0 Then
>        MsgBox MSG_NO_TASKS, Buttons:=vbCritical + R_TO_L,
> Title:=Application.Name
>        End
>    End If
>
>
> Dim Temp As Long, Temp2 As Long
> Dim R As Long, Names As String, FinishDate As Date, FinishID As String
>
> For R = 1 To ActiveProject.Resources.Count
>    FinishID = 0
>    FinishDate = 0
>    Names = ActiveProject.Resources(R).Name
>    For Temp = 1 To ActiveProject.Tasks.Count
>        If Not ActiveProject.Tasks(Temp) Is Nothing Then
>            If StrComp(Names, ActiveProject.Tasks(Temp).ResourceNames,
> 1) = 0 Then
>                If DateValue(ActiveProject.Tasks(Temp).Finish) >=
> DateValue(FinishDate) Then
>                    FinishDate = ActiveProject.Tasks(Temp).Finish
>                    FinishID = ActiveProject.Tasks(Temp).ID
>                End If
>            End If
>        End If
>    Next Temp
>    For Temp2 = 1 To ActiveProject.Tasks.Count
>        If Not ActiveProject.Tasks(Temp2) Is Nothing Then
>            If StrComp(Names, ActiveProject.Tasks(Temp2).Name, 1) = 0
>                Then If Not FinishID = 0 Then
>                    ActiveProject.Tasks(Temp2).Predecessors = FinishID
>                End If
>            End If
>        End If
>    Next Temp2
> Next R
>
> End Sub
>
> - John
date: Tue, 3 Jan 2006 10:41:23 -0000   author:   Mike Glen glenATmvps.org

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us