none
Copy and Pasting code for macros

    Question

  • I am using Project 2010 pro.   I want to understand how to paste code that is offered by people in the forums.  I don't get errors, but the macros don't change anything when I run them.  What is the process?   I see people mentioning "VBA line continuation when you copy and paste code", and I thought that may have something to do with my issue.

    Long Live America

    Wednesday, April 11, 2012 6:37 PM

Answers

  • OK so the code is supposed to set the Flag1 field to true if the task has a Finish-to-Finish or Finish-to-Start link to another task, is that right?

    It works for me.

    it will only work for the active project. So if you have a blank project open and another project with tasks and the blank one is the active project when you run this then it will run on the blank one.

    Try running this code and see what message pops up when you run it.

    Sub NoF()
    Dim Job As Task
    Dim TD As TaskDependency
    
    MsgBox "Active Project: " & ActiveProject.Name
    
    
    For Each Job In ActiveProject.Tasks
        If Not Job Is Nothing Then
            Job.Flag1 = False
            For Each TD In Job.TaskDependencies
                If TD.Type = pjFinishToFinish Or TD.Type = pjFinishToStart Then
                    Job.Flag1 = True
                    Exit For
                End If
            Next TD
        End If 'nothing
    Next Job
    End Sub
    


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Wednesday, April 11, 2012 7:29 PM
    Moderator

All replies

  • Can you paste in an example of the code you are talking about? if it was a line continuation issue I would expect errors. Im guessing that it might be about the code and the project that is active when you run it.


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Wednesday, April 11, 2012 7:13 PM
    Moderator
  • Yes,

    Here is an example related to tasks with no successor:

    Sub NoF()
    Dim Job As Task
    Dim TD As TaskDependency
    For Each Job In ActiveProject.Tasks
    If Not Job Is Nothing Then
    Job.Flag1 = False
    For Each TD In Job.TaskDependencies
    If TD.Type = pjFinishToFinish Or TD.Type = pjFinishToStart Then
    Job.Flag1 = True
    Exit For
    End If
    Next TD
    End If 'nothing
    Next Job
    End Sub


    Long Live America

    Wednesday, April 11, 2012 7:21 PM
  • OK so the code is supposed to set the Flag1 field to true if the task has a Finish-to-Finish or Finish-to-Start link to another task, is that right?

    It works for me.

    it will only work for the active project. So if you have a blank project open and another project with tasks and the blank one is the active project when you run this then it will run on the blank one.

    Try running this code and see what message pops up when you run it.

    Sub NoF()
    Dim Job As Task
    Dim TD As TaskDependency
    
    MsgBox "Active Project: " & ActiveProject.Name
    
    
    For Each Job In ActiveProject.Tasks
        If Not Job Is Nothing Then
            Job.Flag1 = False
            For Each TD In Job.TaskDependencies
                If TD.Type = pjFinishToFinish Or TD.Type = pjFinishToStart Then
                    Job.Flag1 = True
                    Exit For
                End If
            Next TD
        End If 'nothing
    Next Job
    End Sub
    


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Wednesday, April 11, 2012 7:29 PM
    Moderator
  • it says compile error syntax error.  do i copy from sub NoF() thru End Sub, click macro, edit macro and paste in the window, then close VB?


    Long Live America

    Wednesday, April 11, 2012 7:33 PM
  • It had a dotted line after End Sub, i removed that and it ran ok.  The msg was Active Project: filepath  So it seems I am pasting properly.

    Long Live America

    Wednesday, April 11, 2012 7:36 PM
  • Does the project called Filepath actually contain tasks that have Finish-to-finish or Finish-to-Start links?

    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Wednesday, April 11, 2012 7:37 PM
    Moderator
  • yes, many FS tasks

    Long Live America

    Wednesday, April 11, 2012 7:39 PM
  • What is the value of Flag1 for these tasks?


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Wednesday, April 11, 2012 7:42 PM
    Moderator
  • They appear to all be Yes, but their summary tasks are No.

    Long Live America

    Wednesday, April 11, 2012 7:48 PM
  • Cool. Then your code is working as expected. The summary tasks being now is expected since they dont have any links.

    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Wednesday, April 11, 2012 7:58 PM
    Moderator
  • Thank You

    Long Live America

    Wednesday, April 11, 2012 8:03 PM