Window Activate Function

J

Jeff Fenbert

I am writing a macro to copy data from one file to
another. As part of the process I need to switch between
active windows. The macro has crashed depending on what
machine the macro runs. I have traced the problem to the
file name.

I defined a varible based on the activeproject name. In
some machines the active name is "projectname" on others
it appears to be "projectname.mpp" This causes the macro
to crash on some machines when the line says:

WindowActivate projectname

To work on that machine I have put in

WindowActivate projectname + .mpp

Am I using the property correctly?
Any better ideas on how to switch windows?

thanks.
 
J

Jeff Fenbert

The first file contains some task information that needs
to be copied into the second file. Specifically it is
some date information. We do not want to link directly to
the other files using the link between projects
information.


Using the WindowActivate function was the only way I could
think of to let Project know which file to copy from and
which file to copy to. Is there a better way to do this?
 
J

JackD

The following code sets proj1 to the activeproject (the one which is open)
It then sets proj2 to another project (enter your own filepath instead of
the one I used)
Then it copies the finish of the fifth task in proj1 to the date1 field of
the fifth task in proj2.
Of course you need to modify this so that it meets your specific needs, but
there is no reason for you to activate either of the projects if you are
merely copying data over.

Sub myproj()
Dim proj1, proj2 As Project
Set proj1 = ActiveProject
Set proj2 = FileOpen("c:\myfilename.mpp")
proj2.Tasks(5).Date1 = proj1.Tasks(5).Finish
End Sub

You could also do something like this:
Set proj1 = Application.Projects(1)
Set proj2 = Application.Projects(2)

but you would have to make sure that the projects were opened in the correct
order or things would go backwards :)

-Jack
 
J

Jeff Fenbert

Thank you that is helpful.

Another question.

Is there a way to copy the information if you know the
uniqueID of a task instead of the ID number?
 
J

JackD

I think you can "find" that task and get the id number or you can iterate
through the tasks until you find that id number or you can filter the tasks
in the other project for that UID number, select and then get the task
reference from the active selection (an example of the last is on my website
in the Monte Carlo Simulation macro
You can find it here at the bottom of the page.
http://masamiki.com/macros.htm

-Jack
 
J

Jeff Fenbert

Thanks. I had used the iterate through method. I had run
into trouble with the filter function. If projects were
filtered, it could not find the task.
 

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