none
add task to selection RRS feed

  • Question

  • using msp 2003/2007

    Is there a way to clear the current ActiveSelection and add a task by Unique id to the Active selection? (like in highlighting the task)

     

    thx!

    Thursday, August 12, 2010 1:06 PM

All replies

  • Hi,
     
    I recorded a macro of me doing this manually and got:
     
    SelectTaskField Row:=-2, Column:="Name", Add:=True

    --

    Rod Gill
    Microsoft MVP for Project - http://www.project-systems.co.nz
     
    Author of the only book on Project VBA, see: http://www.projectvbabook.com
     

     

    using msp 2003/2007

    Is there a way to clear the current ActiveSelection and add a task by Unique id to the Active selection? (like in highlighting the task)

     

    thx!



    __________ Information from ESET Smart Security, version of virus signature database 5362 (20100813) __________

    The message was checked by ESET Smart Security.

    http://www.eset.com

    The one and only Project VBA Book Rod Gill Project Management
    Friday, August 13, 2010 9:00 AM
    Moderator
  • The thing is:

     

    the only way to be certain you have the correct task selected is by Unique Id.

    So i can loop through all tasks checking if the current task has the desired Unique Id. If so, I want that task to be highlighted.

    Is there a way to highlight the current task in a loop?

    Btw. i'm using ruby and VBA. Example code:

     

    $mspproject.tasks.each{|task|
    unless task==nil
    
    if task.UniqueID.to_s==5
          $mspapplication.SelectRow(task.Id-1,false) #(task id starts at 1, rows start at 0)?????QUESTIONABLE
    end
    end

     

    Thursday, August 19, 2010 2:09 PM
  • I thought you jest wanted to add a task to the current selection? The sample code I posted does just that.
     
    If you have a Unique ID and want its ID use:
     
    ActiveProject.tasks.UniqueID(UniqueIdNumber).Id
     
    What's Ruby? Its code looks... well shall we say just not easy to read?!! ;-)

    --

    Rod Gill
    Microsoft MVP for Project - http://www.project-systems.co.nz
     
    Author of the only book on Project VBA, see: http://www.projectvbabook.com
     

     

    The thing is:

     

    the only way to be certain you have the correct task selected is by Unique Id.

    So i can loop through all tasks checking if the current task has the desired Unique Id. If so, I want that task to be highlighted.

    Is there a way to highlight the current task in a loop?

    Btw. i'm using ruby and VBA. Example code:

     

    $mspproject.tasks.each{|task|
    unless task==nil
    
    if task.UniqueID.to_s==5
       $mspapplication.SelectRow(task.Id-1,false) #(task id starts at 1, rows start at 0)?????QUESTIONABLE
    end
    end

     



    __________ Information from ESET Smart Security, version of virus signature database 5383 (20100820) __________

    The message was checked by ESET Smart Security.

    http://www.eset.com

    The one and only Project VBA Book Rod Gill Project Management
    Saturday, August 21, 2010 7:14 AM
    Moderator
  • Thx again for your answer.

    I'll explain what i want to do:

    I have a set of numbers: 1,45,78,14 which are unique id's of tasks. Now i want each of these tasks to be 'selected'  in MS Project through VB
    if i'm not mistaking you can only manipulate the selected tasks with SelectRow(number of the row)

    I do not know what row the tasks with the specified unique id is in. So it this moment I loop through all tasks, check if the number matches the unique id, if so i want to highlight (select) the row of that task.

    In fact it would be great if there was a command like SelectRowByUniqueId(uniqueid)

    Concerning ruby: http://www.ruby-lang.org/en/

     

    Monday, August 23, 2010 12:48 PM
  • Hi,

    The way you do it is good. Attention though, ID is not always equal to row number. Look out for Filters, Sorts, and the project summary task.

    Monday, August 23, 2010 6:43 PM
    Moderator
  • If by row number you mean the id number displayed in the leftmost column, my previous post did what you want. If you mean the nth task down from teh top of the screen, Jan is correct in that a filter will spoil your day!
     
    If you have a Unique ID and want its ID use:
     
    ActiveProject.tasks.UniqueID(UniqueIdNumber).Id

    --

    Rod Gill
    Microsoft MVP for Project - http://www.project-systems.co.nz
     
    Author of the only book on Project VBA, see: http://www.projectvbabook.com
     

     

    Thx again for your answer.

    I'll explain what i want to do:

    I have a set of numbers: 1,45,78,14 which are unique id's of tasks. Now i want each of these tasks to be 'selected'  in MS Project through VB
    if i'm not mistaking you can only manipulate the selected tasks with SelectRow(number of the row)

    I do not know what row the tasks with the specified unique id is in. So it this moment I loop through all tasks, check if the number matches the unique id, if so i want to highlight (select) the row of that task.

    In fact it would be great if there was a command like SelectRowByUniqueId(uniqueid)

    Concerning ruby: http://www.ruby-lang.org/en/

     



    __________ Information from ESET Smart Security, version of virus signature database 5391 (20100823) __________

    The message was checked by ESET Smart Security.

    http://www.eset.com

    The one and only Project VBA Book Rod Gill Project Management
    Tuesday, August 24, 2010 9:56 AM
    Moderator
  • jan en rod, thx for answering.

     

    If i understand correct there is no easy way to select a task by it's unique id without the problems of filtering, sorting, etc since you can only select by Row number and not by task id or  unique id?!

     

    A additional question: is it possible to clear the current selection?

    Let's say row 1 is selected and i only want row 5 and 7 to be selected, how do i do that? i tried like this:

    SelectRow(5,false,'0',false,true)

    SelectRow(7,false,'0',false,true)

     

    but this also give row 1 still selected

    Tuesday, August 24, 2010 11:44 AM
  • You can do it by selecting all tasks, looping thru the selection and keeping a record of the row number of all your Unique IDs. yes it can be done, but its cumbersome. Maybe the better approach is: why do you want to select tasks. VBA can do almost everything without selecting a single task. Usually the only valid reason is you want to select specific tasks so the user can see them.
     
    Consider then creating a filter on a flag field that highlights filtered tasks instead. You VBA sets relevant Task's Flag field, apply the filter and these tasks are automatically highlighted.
     
    For your other answers please record a macro of you selecting and de-selecting various tasks and you will get exactly what you need. Note however, that selecting different tasks is a very inefficient and slow way of writing VBA code. Almost all VBA actions can be done without selecting any tasks.

    --

    Rod Gill
    Microsoft MVP for Project - http://www.project-systems.co.nz
     
    Author of the only book on Project VBA, see: http://www.projectvbabook.com
     

     

    jan en rod, thx for answering.

     

    If i understand correct there is no easy way to select a task by it's unique id without the problems of filtering, sorting, etc since you can only select by Row number and not by task id or  unique id?!

     

    A additional question: is it possible to clear the current selection?

    Let's say row 1 is selected and i only want row 5 and 7 to be selected, how do i do that? i tried like this:

    SelectRow(5,false,'0',false,true)

    SelectRow(7,false,'0',false,true)

     

    but this also give row 1 still selected



    __________ Information from ESET Smart Security, version of virus signature database 5394 (20100824) __________

    The message was checked by ESET Smart Security.

    http://www.eset.com

    The one and only Project VBA Book Rod Gill Project Management
    Tuesday, August 24, 2010 10:03 PM
    Moderator