Copy and Pasting code for macros
-
Wednesday, April 11, 2012 6:37 PMI 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
All Replies
-
Wednesday, April 11, 2012 7:13 PMModerator
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:21 PM
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 SubLong Live America
-
Wednesday, April 11, 2012 7:29 PMModerator
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 SubBrian Kennemer - Project MVP
DeltaBahn Senior Architect
endlessly obsessing about Project Server…so that you don’t have to.
Blog | Twitter | LinkedIn- Marked As Answer by Vassily Zeitsev Wednesday, April 11, 2012 8:02 PM
-
Wednesday, April 11, 2012 7:33 PM
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:36 PMIt 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:37 PMModerator
-
Wednesday, April 11, 2012 7:39 PMyes, many FS tasks
Long Live America
-
Wednesday, April 11, 2012 7:42 PMModerator
-
Wednesday, April 11, 2012 7:48 PMThey appear to all be Yes, but their summary tasks are No.
Long Live America
-
Wednesday, April 11, 2012 7:58 PMModerator
-
Wednesday, April 11, 2012 8:03 PMThank You
Long Live America

