<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>projectified : Project 2007</title><link>http://blogs.technet.com/projectified/archive/tags/Project+2007/default.aspx</link><description>Tags: Project 2007</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Moving Tasks With VBA</title><link>http://blogs.technet.com/projectified/archive/2008/10/06/3133229.aspx</link><pubDate>Tue, 07 Oct 2008 06:17:09 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3133229</guid><dc:creator>brianken</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/projectified/comments/3133229.aspx</comments><wfw:commentRss>http://blogs.technet.com/projectified/commentrss.aspx?PostID=3133229</wfw:commentRss><wfw:comment>http://blogs.technet.com/projectified/rsscomments.aspx?PostID=3133229</wfw:comment><description>&lt;p&gt;So the problem was that a customer wanted to be able to move a task that was at ID 7 and move it so that it was at ID 2. Sadly, VBA for Project does not contain a Task.Move method. But with a little bit of code around them you can use a Cut and Paste methods for Rows.&lt;/p&gt;  &lt;p&gt;The example below assumes that you know the name of the task you want to move and the name of the task that currently occupies the row where you want to move the first task. &lt;/p&gt;  &lt;p&gt;Here is a sample task list. This sample is a good test because the tasks are out of ID order. The task I want to move (name = 7) is in ID position 3 and I want to move it to where Task 2 is now (currently in ID position 9.)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.technet.com/blogfiles/projectified/WindowsLiveWriter/MovingTasksWithVBA_11CF6/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.technet.com/blogfiles/projectified/WindowsLiveWriter/MovingTasksWithVBA_11CF6/image_thumb.png" width="113" height="226" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Arial"&gt;Sub TaskMover()     &lt;br /&gt;Dim t As Task      &lt;br /&gt;Dim NewID As Integer &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Arial"&gt;For Each t In ActiveProject.Tasks     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; If Not (t Is Nothing) Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If t.Name = 2 Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; NewID = t.ID      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If t.Name = 7 Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SelectRow Row:=t.ID, Rowrelative:=False      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EditCut      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;Next t &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Arial"&gt;SelectRow Row:=NewID, Rowrelative:=False     &lt;br /&gt;EditPaste &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Arial"&gt;End Sub&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This code is not very elegant in that it requires us to select a row and then cut it and then select another row and then paste it. It also requires that the view in the activewindow is a Task view. There is some code we can use to test to make sure the view is the right type. “ActiveWindow.TopPane.View.Type” should be “0” or “pjTaskItem”. So it is not perfect but it gets the job done. You can use this as a starting point for your own needs.&lt;/p&gt;  &lt;p&gt;So the new code with this view type test would look like this:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Arial"&gt;Sub TaskMover()     &lt;br /&gt;Dim t As Task      &lt;br /&gt;Dim NewID As Integer      &lt;br /&gt;If ActiveWindow.TopPane.View.Type = pjTaskItem Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; For Each t In ActiveProject.Tasks      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If Not (t Is Nothing) Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If t.Name = 2 Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; NewID = t.ID      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If t.Name = 7 Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SelectRow Row:=t.ID, Rowrelative:=False      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; EditCut      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Next t      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SelectRow Row:=NewID, Rowrelative:=False      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; EditPaste      &lt;br /&gt;End If      &lt;br /&gt;End Sub&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3133229" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/projectified/archive/tags/VBA/default.aspx">VBA</category><category domain="http://blogs.technet.com/projectified/archive/tags/Project+2007/default.aspx">Project 2007</category></item></channel></rss>