Data Transfer Between Two Files

J

Jimmy

Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get that
to work.

Thanks in advance.
 
R

Rod Gill

Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub
 
J

Jimmy

I see. In your second test for blank lines:
if not aTask is nothing ....
You meant bTask, correct? Otherwise we test aTask twice and never bTask.
I would never have thought to test for a blank line, Thanks!

I also tried this with some success:

For Each aTask In Application.Projects.Item(SourceIndex).Tasks

where I use an integer to identify the source and destination files ... my
code is hard coded as 1 or 2, but I could easily modify it to ask the user
for the number.

Again, thank you for the help.


Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Jimmy said:
Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get
that
to work.

Thanks in advance.
 
J

John

Jimmy said:
I see. In your second test for blank lines:
if not aTask is nothing ....
You meant bTask, correct? Otherwise we test aTask twice and never bTask.
I would never have thought to test for a blank line, Thanks!

I also tried this with some success:

For Each aTask In Application.Projects.Item(SourceIndex).Tasks

where I use an integer to identify the source and destination files ... my
code is hard coded as 1 or 2, but I could easily modify it to ask the user
for the number.

Again, thank you for the help.

Jimmy,
Let me just pop in here since Rod is probably sleeping (time zone
thing). Rod's code is correct as writtne. His code indexes through both
the a.mpp file and the b.mpp file. the "If Not atask is Nothing"
increments around blank lines to sync the a.mpp file back up with the
b.mpp file. A similar thing happens with the "If Not btask is Nothing".
in the inner loop.

I would have sorted both files by the Unique ID and then started the
loops. This will run a little more efficiently since the inner loop
doesn't have to go through the entire b.mpp file for each a.mpp task.
But then you also have to deal with missing or changed Unique ID values.

Hope this helps.
John
Project MVP
Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Jimmy said:
Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get
that
to work.

Thanks in advance.
 
R

Rod Gill

Unique IDs get changed every time you copy and paste. Dragging with a mouse
is okay though.

--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


John said:
Jimmy said:
I see. In your second test for blank lines:
if not aTask is nothing ....
You meant bTask, correct? Otherwise we test aTask twice and never bTask.
I would never have thought to test for a blank line, Thanks!

I also tried this with some success:

For Each aTask In Application.Projects.Item(SourceIndex).Tasks

where I use an integer to identify the source and destination files ...
my
code is hard coded as 1 or 2, but I could easily modify it to ask the
user
for the number.

Again, thank you for the help.

Jimmy,
Let me just pop in here since Rod is probably sleeping (time zone
thing). Rod's code is correct as writtne. His code indexes through both
the a.mpp file and the b.mpp file. the "If Not atask is Nothing"
increments around blank lines to sync the a.mpp file back up with the
b.mpp file. A similar thing happens with the "If Not btask is Nothing".
in the inner loop.

I would have sorted both files by the Unique ID and then started the
loops. This will run a little more efficiently since the inner loop
doesn't have to go through the entire b.mpp file for each a.mpp task.
But then you also have to deal with missing or changed Unique ID values.

Hope this helps.
John
Project MVP
Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank
row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task -
blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp
was
created from a.mpp and entire groups of tasks were added/deleted,
moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from
a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the
data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to
get
that
to work.

Thanks in advance.
 
J

John

Rod Gill said:
Unique IDs get changed every time you copy and paste. Dragging with a mouse
is okay though.
Rod,
That's why I put in the "disclaimer" about dealing with Unique ID
exceptions.

John
John said:
Jimmy said:
I see. In your second test for blank lines:
if not aTask is nothing ....
You meant bTask, correct? Otherwise we test aTask twice and never bTask.
I would never have thought to test for a blank line, Thanks!

I also tried this with some success:

For Each aTask In Application.Projects.Item(SourceIndex).Tasks

where I use an integer to identify the source and destination files ...
my
code is hard coded as 1 or 2, but I could easily modify it to ask the
user
for the number.

Again, thank you for the help.

Jimmy,
Let me just pop in here since Rod is probably sleeping (time zone
thing). Rod's code is correct as writtne. His code indexes through both
the a.mpp file and the b.mpp file. the "If Not atask is Nothing"
increments around blank lines to sync the a.mpp file back up with the
b.mpp file. A similar thing happens with the "If Not btask is Nothing".
in the inner loop.

I would have sorted both files by the Unique ID and then started the
loops. This will run a little more efficiently since the inner loop
doesn't have to go through the entire b.mpp file for each a.mpp task.
But then you also have to deal with missing or changed Unique ID values.

Hope this helps.
John
Project MVP
:

Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank
row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task -
blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp
was
created from a.mpp and entire groups of tasks were added/deleted,
moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from
a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the
data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to
get
that
to work.

Thanks in advance.
 
T

Tom

Rod,

I am new to VBA. I tried the codes below but they do not seem to work. It
appears that both active projects are the same. What am I doing wrong?

Thanks.

Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Jimmy said:
Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get
that
to work.

Thanks in advance.
 
J

John

Tom said:
Rod,

I am new to VBA. I tried the codes below but they do not seem to work. It
appears that both active projects are the same. What am I doing wrong?

Thanks.

Tom,
"Do not seem to work", that's a pretty general statement. It gives us
absolutely nothing to go on. More details are needed.

John
Project MVP
Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Jimmy said:
Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get
that
to work.

Thanks in advance.
 
T

Tom

John,

I would like to transfer the following data (such as Text1, % complete) from
project A to project B. I used the codes that Rod provided below. When I
ran them, the macro did open the two files. However, none of the data was
transferred from project A to project B.

Thanks.


John said:
Tom said:
Rod,

I am new to VBA. I tried the codes below but they do not seem to work. It
appears that both active projects are the same. What am I doing wrong?

Thanks.

Tom,
"Do not seem to work", that's a pretty general statement. It gives us
absolutely nothing to go on. More details are needed.

John
Project MVP
Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get
that
to work.

Thanks in advance.
 
R

Rod Gill

Your first post suggested you did a lot of copy/paste. This means the tasks
now have different unique ids. How many tasks have the same unique id in
both files, can you check manually?

--

Rod Gill
Project MVP

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


Tom said:
John,

I would like to transfer the following data (such as Text1, % complete)
from
project A to project B. I used the codes that Rod provided below. When I
ran them, the macro did open the two files. However, none of the data was
transferred from project A to project B.

Thanks.


John said:
Tom said:
Rod,

I am new to VBA. I tried the codes below but they do not seem to work.
It
appears that both active projects are the same. What am I doing wrong?

Thanks.

Tom,
"Do not seem to work", that's a pretty general statement. It gives us
absolutely nothing to go on. More details are needed.

John
Project MVP
:

Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank
row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task -
blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp
was
created from a.mpp and entire groups of tasks were added/deleted,
moved,
%Complete ....

Now, we need to recover some of the information from the old file
and
figure
the best way to do it is to write the information back to b.mpp
from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the
data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to
get
that
to work.

Thanks in advance.
 
T

Tom

Rod,

There are approximately 420 tasks that have the same unique ID in both files.
I actually did not use a lot of the copy/paste function.


Rod Gill said:
Your first post suggested you did a lot of copy/paste. This means the tasks
now have different unique ids. How many tasks have the same unique id in
both files, can you check manually?

--

Rod Gill
Project MVP

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


Tom said:
John,

I would like to transfer the following data (such as Text1, % complete)
from
project A to project B. I used the codes that Rod provided below. When I
ran them, the macro did open the two files. However, none of the data was
transferred from project A to project B.

Thanks.


John said:
Rod,

I am new to VBA. I tried the codes below but they do not seem to work.
It
appears that both active projects are the same. What am I doing wrong?

Thanks.

Tom,
"Do not seem to work", that's a pretty general statement. It gives us
absolutely nothing to go on. More details are needed.

John
Project MVP

:

Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank
row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task -
blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp
was
created from a.mpp and entire groups of tasks were added/deleted,
moved,
%Complete ....

Now, we need to recover some of the information from the old file
and
figure
the best way to do it is to write the information back to b.mpp
from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the
data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to
get
that
to work.

Thanks in advance.
 
T

Tom

Rod and John,

Thank you for your helps. I figured it out.

Tom said:
Rod,

There are approximately 420 tasks that have the same unique ID in both files.
I actually did not use a lot of the copy/paste function.


Rod Gill said:
Your first post suggested you did a lot of copy/paste. This means the tasks
now have different unique ids. How many tasks have the same unique id in
both files, can you check manually?

--

Rod Gill
Project MVP

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


Tom said:
John,

I would like to transfer the following data (such as Text1, % complete)
from
project A to project B. I used the codes that Rod provided below. When I
ran them, the macro did open the two files. However, none of the data was
transferred from project A to project B.

Thanks.


:

Rod,

I am new to VBA. I tried the codes below but they do not seem to work.
It
appears that both active projects are the same. What am I doing wrong?

Thanks.

Tom,
"Do not seem to work", that's a pretty general statement. It gives us
absolutely nothing to go on. More details are needed.

John
Project MVP

:

Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank
row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task -
blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp
was
created from a.mpp and entire groups of tasks were added/deleted,
moved,
%Complete ....

Now, we need to recover some of the information from the old file
and
figure
the best way to do it is to write the information back to b.mpp
from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the
data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I
can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to
get
that
to work.

Thanks in advance.
 
J

John

Tom said:
Rod and John,

Thank you for your helps. I figured it out.

Tom,
Although Rod provided all the relevant help, thanks anyway.
John
Tom said:
Rod,

There are approximately 420 tasks that have the same unique ID in both
files.
I actually did not use a lot of the copy/paste function.


Rod Gill said:
Your first post suggested you did a lot of copy/paste. This means the
tasks
now have different unique ids. How many tasks have the same unique id in
both files, can you check manually?

--

Rod Gill
Project MVP

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


John,

I would like to transfer the following data (such as Text1, % complete)
from
project A to project B. I used the codes that Rod provided below.
When I
ran them, the macro did open the two files. However, none of the data
was
transferred from project A to project B.

Thanks.


:

Rod,

I am new to VBA. I tried the codes below but they do not seem to
work.
It
appears that both active projects are the same. What am I doing
wrong?

Thanks.

Tom,
"Do not seem to work", that's a pretty general statement. It gives us
absolutely nothing to go on. More details are needed.

John
Project MVP

:

Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task -
blank
row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task -
blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think
I
can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Assume I open two files in MSProject2003. a.mpp and b.mpp.
b.mpp
was
created from a.mpp and entire groups of tasks were
added/deleted,
moved,
%Complete ....

Now, we need to recover some of the information from the old
file
and
figure
the best way to do it is to write the information back to b.mpp
from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging
the
data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I
think I
can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem
to
get
that
to work.

Thanks in advance.
 
S

SpaceCamel

Instead of looping thru the second project why not just:

Set bTask = bProject.Tasks.UniqueID(aUID)

---------------------------------------

Rod Gill said:
Hi,

Try:

Public Sub CorrectIt()
Dim aProject As Project
Dim bProject As Project
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
set aProject =activeproject
FileOpen("E:\b.mpp")
set bProject =activeproject

For Each aTask In aProject .Tasks 'Assume a.mpp
if not atask is nothing then 'Test for empty task - blank row
For Each bTask In bProject .Tasks 'Assume b.mpp
if not atask is nothing then 'Test for empty task - blank row
If (aTask.UniqueID = btask.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can work
that.
End If
End If
Next bTask
End IF
Next aTask
End Sub



--

Rod Gill
Microsoft MVP for Project
The book on Project VBA http://www.projectvbabook.com


Jimmy said:
Assume I open two files in MSProject2003. a.mpp and b.mpp. b.mpp was
created from a.mpp and entire groups of tasks were added/deleted, moved,
%Complete ....

Now, we need to recover some of the information from the old file and
figure
the best way to do it is to write the information back to b.mpp from a.mpp
using VBA.

What I want to do is update inforamtion in a.mpp be examinging the data in
b.mpp
Here is what I have so far in a.mpp, but it will not compile:
[Both of these projects are open in Project]

Public Sub CorrectIt()
Dim OtherFile As Project
'It Dies on the next line of code:
OtherFile.FullName = FileOpen("E:\b.mpp")
Dim aTask As Task 'Task Collection in a.mpp
Dim bTask As Task 'Task Collection in b.mpp
On Error Resume Next
For Each aTask In ActiveProject.Tasks 'Assume a.mpp
For Each bTask In OtherFile.Tasks 'Assume b.mpp
If (aTask.UniqueID = b.UniqueID) Then
b.Text15 = a.Text15
'There are others .... %Complete, Actual Start, etc. But I think I can
work
that.
End If
Next bTask
Next aTask
End Sub

I am thinking I need to use the Projects object, but can't seem to get
that
to work.

Thanks in advance.
 

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