none
How to insert a subproject with VBA? RRS feed

  • Question

  • hi,

    How does the SelectTaskField function works ?

    I want to insert a small project under the last task (ID = 70) but the project is  insert twice : at the row 138 and at the row 276.

    Sub test()
        SelectTaskField Row:=Projects("Transports.mpp").Tasks.Count, Column:="Indicators"

        ConsolidateProjects Filenames:="C:\Users\Documents\Suubproject.mpp", NewWindow:=False, AttachToSources:=False, HideSubtasks:=True
        OutlineShowSubTasks

    End Sub

    Thanks


    • Edited by WLID1966 Wednesday, February 27, 2019 8:29 PM
    Wednesday, February 27, 2019 4:27 PM

Answers

  • WLID1966,

    In your code, you have left out the RowRelative argument for SelectTaskField, so the method adopts its default value of TRUE.  I think you want to explicitly include RowRelative:=FALSE in your SelectTaskField call.

    Even so, this method presumes that the row number of the current table corresponds exactly to the ID of the task in the ActiveProject - not always correct.  You may have better luck with Application.EditGoTo(ActiveProject.Tasks.Count).  In any case, you'll need some error traps to handle the oddball cases.  Good luck, tom

    • Marked as answer by WLID1966 Thursday, February 28, 2019 11:17 AM
    Wednesday, February 27, 2019 6:32 PM
  • Hi,

    please try the following:

    Dim T As Task
    Set T = ActiveProject.Tasks(71) 'Number is "before"
    SelectRow Row:=T.ID, RowRelative:=False
    ConsolidateProjects Filenames:="C:\Users\User\Documents\Suubproject.mpp", NewWindow:=False, AttachToSources:=False, HideSubtasks:=True
    OutlineShowSubTasks

    Regards
    Barbara

    • Marked as answer by WLID1966 Thursday, February 28, 2019 11:17 AM
    Wednesday, February 27, 2019 6:41 PM
    Moderator

All replies

  • WLID1966,

    In your code, you have left out the RowRelative argument for SelectTaskField, so the method adopts its default value of TRUE.  I think you want to explicitly include RowRelative:=FALSE in your SelectTaskField call.

    Even so, this method presumes that the row number of the current table corresponds exactly to the ID of the task in the ActiveProject - not always correct.  You may have better luck with Application.EditGoTo(ActiveProject.Tasks.Count).  In any case, you'll need some error traps to handle the oddball cases.  Good luck, tom

    • Marked as answer by WLID1966 Thursday, February 28, 2019 11:17 AM
    Wednesday, February 27, 2019 6:32 PM
  • Hi,

    please try the following:

    Dim T As Task
    Set T = ActiveProject.Tasks(71) 'Number is "before"
    SelectRow Row:=T.ID, RowRelative:=False
    ConsolidateProjects Filenames:="C:\Users\User\Documents\Suubproject.mpp", NewWindow:=False, AttachToSources:=False, HideSubtasks:=True
    OutlineShowSubTasks

    Regards
    Barbara

    • Marked as answer by WLID1966 Thursday, February 28, 2019 11:17 AM
    Wednesday, February 27, 2019 6:41 PM
    Moderator
  • Thanks a lot ! That works !
    Thursday, February 28, 2019 11:29 AM