Macro: Entering Predecessor without using specific Task IDs?

N

Nina

I'm having a problem creating a marco that allows me to enter a predecessor
by relative position to currently selected task. The VB code shows:

SetTaskField Field:="Predecessors", Value:="45FS+0d", AllSelectedTasks:=True

What I want to do is instead of using the actual task ID "45", I want the
macro to always choose a task which is certain numbers of rows above the
current position. Is this possible and if so how can I do this?


Nina
 
J

Jim Aksel

Since "45FS+0d" is a string, try something like this:

Dim myString as String
myString=Dim myString As String
myString = Str(Application.ActiveSelection.Tasks.Item(1).ID - 3) + "FS" +
"+3d"
SetTaskField Field:="Predecessors", Value:=myString, AllSelectedTasks:=True

Here you will still run into problems if the TaskID is less than 3 so you
could bury it in an IF statement. You can also use other methods to divine
the 3d or even the FS.

This solution should work if exactly one task has been selected and the
macro run. Otherwise you will need to develop a For Each loop.

Post back if you need more help

--
If this post was helpful, please consider rating it.

Jim

Visit http://project.mvps.org/ for FAQs and more information
about Microsoft Project
 
N

Nina

Thanks Jim! This is *exactly* what I needed, and a quick test showed that it
works!! Thank you!


Nina
 
J

Jim Aksel

Thank you for the feedback.
By the way, I seem to have copied some extraneous code:

myString=Dim myString As String

it is not necessary to dimension myString twice
--
If this post was helpful, please consider rating it.

Jim

Visit http://project.mvps.org/ for FAQs and more information
about Microsoft Project
 

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