Bookmark a Task

J

JJ

I want to created a "bookmark" for a selected task. I'm going to store
the ID or Unique ID (UID) in a global variable. I don't want to use a
field to set a bookmark because I don't want to unnecessarily take up a
data field if I don't have to.

Here's my problem: Using VBA, I'm trying to capture the UID or ID of
the selected task, but it seems like I need to know the ID of the
selected task. It's a circular problem. How do I get around this? Do I
need to step through the tasks one by one in order to determine what
the ID is?

Any help would be appreciated!
JJ
 
R

Rod Gill

Hi,

To read a task's UID:
lngTaskUID=Activeproject.Tasks(1).UniqueID

To read the UID of the selected task:
lngTaskUID=activecell.Task.UniqueID

To read a Task's name when you know its UID only:
MsgBox "Task Name is: " & ActiveProject.Tasks.UniqueID(2).Name

Is this what you want?

--

Rod Gill
Project MVP

NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com
 
J

JJ

Just to clarify...
To read a task's UID:
lngTaskUID=Activeproject.Tasks(1).UniqueID
***** I use this if I know the task's ID and want to retrieve the
task's UID.
To read the UID of the selected task:
lngTaskUID=activecell.Task.UniqueID
***** I use this if I don't know the task's ID but I want to pull the
UID of the active or selected task.
To read a Task's name when you know its UID only:
MsgBox "Task Name is: " & ActiveProject.Tasks.UniqueID(2).Name
***** I use this if I want to pull task data based on knowing only the
UID.

So, how do I select or make active a task if I know the UID?

Thanks for all of your help!

Jeff Rodrigo
 
G

Gérard Ducouret

Hi Jeff,

I would try the following :

Sub SelTache()
Dim lngTaskUID As Long, lngTaskID As Long
Dim oTache As Task
lngTaskUID = 8 'for example
lngTaskID = ActiveProject.Tasks.UniqueID(lngTaskUID).ID
SelectTaskCell Row:=lngTaskID, RowRelative:=False
End Sub

Hope this helps,

Gérard Ducouret
 
J

JJ

Thanks! The solution you gave me works. However, I have a slight
problem...

If any of the summary tasks are collapsed, the cell that is selected is
the cell position where it WOULD be if ALL the summary tasks were
expanded. Is there any way to get around this?

Thanks!
Jeff
 
R

Rod Gill

You can do an Application.OutlineShowAllTasks command first to expand all
summary tasks.

--

Rod Gill
Project MVP

NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com


Thanks! The solution you gave me works. However, I have a slight
problem...

If any of the summary tasks are collapsed, the cell that is selected is
the cell position where it WOULD be if ALL the summary tasks were
expanded. Is there any way to get around this?

Thanks!
Jeff
 
J

JJ

Is there any way to do this without expanding all of the summary tasks?
Would stepping through the project file task by task resolve this
problem?

Thanks!
Jeff
 
R

Rod Gill

Your original request asked to select a task. You can't select a task unless
it's visible.

You can show the task you want with:

activeproject.Tasks(4).OutlineParent.OutlineShowSubTasks

but I find that it is less confusing to either show all tasks or keep the
current display unchanged

--

Rod Gill
Project MVP

NEW!! Project VBA Book, for details visit: http://www.projectvbabook.com


Is there any way to do this without expanding all of the summary tasks?
Would stepping through the project file task by task resolve this
problem?

Thanks!
Jeff
 
J

JJ

Thanks for all of your help! Your knowledge is invaluable! I have tried
all the different ways of selecting a bookmarked task, but it seems the
only way to make it work is to display all of the tasks.

Thanks again!
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top