locked
Copy/Paste sequence RRS feed

  • Question

  • MSP2010 Profesional

    I have to alter my schedule to finish room-by-room instead of floor-by-floor. So, I gathered a template of tasks for each room (Paint walls, Hang Ceiling, Install Doors, etc.) and started inserting them into each floor (8 floors, 30+ rooms per floor). Since the sequences were all identical, I thought I'd copy/paste. But, since I like redundancy (and often show tasks without their hierarchy...) I like the room number to be featured in every task ("Hang Ceiling -- 2.C.34.01"), and, I have custom fields for Building, Level, and Room Nbr.

    So, I decide to create a simple vba routine. To make it simple, I want to select a sequence and have it sort of cut/paste that sequence (a hierarchy...) just above the selected sequence (at the same indent level) then change the description, add in the new room number (inputbox...) in both places on each task, then alter each task to have the correct Building and Levels, then set them to be a true sequence (pred/succ.)

    First thing I learn is that the activeselection.tasks collection seems to feed the tasks in order...can I count on that?

    So, I start trying the "activeproject.tasks.add" method. VERY POORLY DOCUMENTED. It has two arguments..."Name", a string, and "Before", no type defined.

      First, I tried omitting it...added the task at the end of the project...OK, but not optimal

      Second, I tried using "Activeselection.tasks(1).ID"...got a syntax error

      Third, I tried using <12> (some random integer I made up...) ...got a syntax error.

      So, what is the type of the "Before" argument?

      Once added, how do I find the ID or UniqueID of the new task, since I have no reference to it?

      How do it set it to fall into the same outlinelevel of the selected series, with the appropriate parent? (Parent is a read-only property, right?)

    Is my whole strategy wrong?


    Jim

    Saturday, July 7, 2012 6:00 AM

Answers

  • Hi,

    One action will reply two questions at the time.

    When you use .add followed by the arguments between parenthesis the method creates an object so you could use:

    set addedtask=activeproject.tasks.add("Name of newcomer",56)

    Before takes any number, that's not your problem.

    Then of course addedtask.ID is what you need to get the number

    It gets the same outlinelevel as the preceeding task (like when you would insert it manually).

    Outlineindent and outlineoutdent then allow you to change the ooutlinelevel.

    Greetings,

    • Marked as answer by JimS-Indy Saturday, July 7, 2012 8:59 AM
    Saturday, July 7, 2012 7:59 AM

All replies

  • Hi,

    One action will reply two questions at the time.

    When you use .add followed by the arguments between parenthesis the method creates an object so you could use:

    set addedtask=activeproject.tasks.add("Name of newcomer",56)

    Before takes any number, that's not your problem.

    Then of course addedtask.ID is what you need to get the number

    It gets the same outlinelevel as the preceeding task (like when you would insert it manually).

    Outlineindent and outlineoutdent then allow you to change the ooutlinelevel.

    Greetings,

    • Marked as answer by JimS-Indy Saturday, July 7, 2012 8:59 AM
    Saturday, July 7, 2012 7:59 AM
  • Jan, 

    Too bad Microsoft ignores Project when it comes to documentation. Thank you for your help. I did determine that my whole strategy was flawed, and recanted it. Here's what I did (though your explanation will help me going forward):

    Sub ReplicateWithNewRoomNbrName() Dim tsk As Task

    Dim strNewRoomNbr As String strNewRoomNbr = InputBox("Next Room Number:") Dim strNewRoomName As String strNewRoomName = InputBox("New Room Name:") Dim strRoomNbrArray() As String strRoomNbrArray = Split(strNewRoomNbr, ".") Dim strNewBuilding As String Dim strNewLevel As String

    ' Room numbers are of the form BLDG.LEVEL.ROOM.Subroom

    strNewBuilding = strRoomNbrArray(0) If strRoomNbrArray(1) = "0" Then strNewLevel = "B1" Else strNewLevel = "F" & strRoomNbrArray(1) End If Dim intModelTaskID As Long Dim intModelTaskUniqueID As Long EditCopy EditPaste Dim strGenericTaskName As String For Each tsk In ActiveSelection.Tasks If tsk.Summary = True Then tsk.Name = strNewRoomNbr & " " & strNewRoomName Else strGenericTaskName = Split(tsk.Name, "--")(0) tsk.Name = strGenericTaskName & "-- " & strNewRoomNbr End If tsk.Text3 = strNewRoomNbr tsk.Text1 = strNewBuilding tsk.Text2 = strNewLevel Next tsk End Sub

    Again, your contribution to my understanding of the .add method will help me. Thank you.


    Jim

    Saturday, July 7, 2012 9:03 AM