How do you keep the Unique ID value like the "move event" with code???

M

MacPhatKat

I noticed if you cut and paste a task in the grid view the Unique ID
will change. However if you select the row using the Grey Row Number
on the far left of the grid, the mouse cursor will change to four
arrows and allow you to drag the task to a new location, after you
drop the task the Unique ID remains the same.

I tried to record a macro to see if this sequence could be captured,
but the drag/drop ability was disabled after the recording started,
and only worked after the recording stopped.

What code would I have to write to duplicate the drag and drop
behavior, and keep the Unique ID after the task has been moved to a
new location?

Any help would be greatly appreciated.
 
J

John

MacPhatKat,
First, let me address cut and paste versus drag and drop. When a cut and
paste is performed the task is effectively deleted from the file and
placed on the clipboard. The Unique ID that task possessed then falls
into a kind of "number not used" cateogry. When the task is pasted back,
it is effectively a new task and gets the "next available" Unique ID. In
one special case, if the task happened to be the last Unique ID, when
pasted back it will retain its Unique ID. On the other hand, drag and
drop simply moves the existing task to another location. It is never
deleted and therefore retains its Unique ID.

Emulating a drag and drop operation in VBA code is possible and there
are probably various ways to do it. There might even be an obscure
method that makes it easier but nothing comes to mind. However, it is
not obvious to me why you would want to emulate a drag and drop in code.
First, there would need to be some type of input (from a user I assume)
defining the from and to. And if that is the case, why not just do it
manually? Second, when working with Project objects in VBA, their
location in the file is generally not relevant. Properties of any task,
resource or assignment can be readily accessed through the object model.

However, off the cuff, if I were to write code to emulate a drag and
drop, I would probably set up a scheme to filter and/or sort the tasks
into the sequence needed. This may take more than one iteration. I would
then permanently renumber the tasks in that order.

Hope this helps.
John
 
M

MacPhatKat

Thank you for your quick response,

I want to emulate drag/drop behavior using COM calls. I have a .Net
wrapper a round the MS Project 10.0 Object Library. For exact reasons
not relevant to this group, I am associating programmatic business
data with a task in my own application using the Unique ID as sort of
a pointer to the task. In certain instances I need to MOVE the task to
below a new summery task. I do this in my own app using the COM calls
so the user doesn't have to open MS Project and do it themselves.

Basically, I'm trying to find that obscure method you mentioned that
would do this move action. I have tried to reassign the ID, Index
number, and Outline Number, but all these properties are read only. I
also can't find a method that's appropriate.

If you could know of, or can find, a way of doing this using code, I
will proclaim you MS Project Developer Guru
 
J

John

MacPhatKat,
I don't know anything about COM calls or .Net so I can't help you there.

I only mentioned that there MAY be an obscure method because
occasionally I will develop a way to do something in VBA and then
discover later that there is a method, function, etc. that will do the
same operation. However, my guess is that it is very unlikely there is a
existing method to facilitate drag and drop in code.

There is no doubt in my mind that drag and drop can be emulated in code
but I don't have a ready method other than to start with the process I
briefly outlined in my original response and go from there. I like this
kind of VBA challenge and if I had the time I would develop it for you,
but, I don't have the time.

John
 
M

MacPhatKat

Thanks for trying,

All the COM calls do are wrap the VBA calls, and .Net wraps the COM
calls. This allows for a developer to code in any language that
supports .Net. Ultimately the API method, properties, objects and
events are the same one VBA uses.

Can you recommend any other developer resources for MS Project that I
may pose my question to?
 
R

Rod Gill

HI,

Looks like no one has come up with a method of moving a task without losing
the original Unique ID. So, there is a workaround:

Using VBA:
Sort by ID
Copy the ID (not Unique) to Number 1 (or any of the other Number fields if
you are already using Number1)
change the Number1 field so that the task you want to move is sequenced to
be where you want it.
Sort by Number1 with the flag renumber tasks set to True.

I think this should work.You'll just have to be clever about renumbering
Number1 field so you end up with the correct sequence.

--
For VBA posts, please use the public.project.developer group.
For any version of Project use public.project
For any version of Project Server use public. project.server

Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
 
J

John

MacPhatKat,
The more I thought about being proclaimed a Guru, the more intrigued I
became. You drew me in. As I mentioned, I don't have time to develop and
test an actual macro but here is the pseudo code I would use. (Does this
mean I get to be a semi-guru?)

1. Designate a spare number field (e.g. Number1) to hold temporary IDs
and clear it before proceeding.
2. Get the Task ID (from wherever) of the line to drag and the Task ID
of the after which it will be dropped. For example, drag Task ID 5 so it
is located immediately after Task ID 20.
3. Using the line numbers in step 2 as an example, copy Task IDs 1
through 4 and 21 and up to the spare number field.
4. Subtract "1" from Task IDs 6 through 20 and copy those to the spare
number field.
5. Put the number 20 in the spare number field for Task ID 5.
6. Sort on the spare number field. Select the option to permanently
renumber tasks

That should do it.

John
 
J

John

MacPhatKat,
Did you read my second post (Sunday, June 27)? In it I outline pseudo
code to do what you want.

john
 

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