Macro Crashes in MSP 2007

P

ProjmanZA

Hi Guys ,

I need help with a Macro i have created. The Macro Crashes if i run it
as one Macro, but if i split it up it works just fine. The problem is
i have to have only 1 Macro with a button on the toolbar to execute
the events. In short i have about 2 editcopy jobs and 2 edit paste
jobs. On the second EditPaste it crashes. Herewith the vba Code

Sub CopyPasteMacro()
' Macro CopyPasteMacro
' Macro Recorded Fri 08/10/17 by MOSS\Administrator.
SelectResourceColumn Column:="Cost Rate Table"
EditCopy
SelectResourceColumn Column:="Text1"
EditPaste
SelectResourceField Row:=1, Column:="Cost Rate Table"
SetTaskField Field:="Cost Rate Table", Value:="C"
SelectResourceField Row:=1, Column:="Cost Rate Table"
SelectResourceField Row:=-1, Column:="Cost Rate Table"
SelectResourceField Row:=0, Column:="Cost Rate Table", Height:=18
FillDown
SelectResourceColumn Column:="Cost"
EditCopy
SelectResourceColumn Column:="Cost1"
EditPaste
SelectResourceColumn Column:="Text1"
EditCopy
SelectResourceColumn Column:="Cost Rate Table"
EditPaste
SelectResourceField Row:=0, Column:="Text1"
SelectResourceField Row:=0, Column:="Text1", Height:=19,
Extend:=True
EditClear Contents:=True
End Sub
 
R

Rod Gill

Hi,

Eventually, this group will close down, so please use the project.developer
group in future.

To answer your question, it looks like you want to create a margin report.
The following macro assumes the internal margin is in Cost B. The Cost to
the customer is assumed to be in Cost column and the internal cost in Cost1.
You need to create a formula in Cost2 to calculate the difference. Run this
macro with a Gantt chart active.

'Set Rate B for every Assignment
For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then
For Each A In Tsk.Assignments
A.Number1 = A.CostRateTable
A.CostRateTable = 1 '1=Rate B
Next A

'Copy new Cost to Cost1
Tsk.Cost1 = Tsk.Cost
End If
Next Tsk

'Reset Rate A as rate for every Assignment
For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then
For Each A In Tsk.Assignments
A.CostRateTable = A.Number1
Next A
End If
Next Tsk

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
P

ProjmanZA

Hi,

Eventually, this group will close down, so please use the project.developer
group in future.

To answer your question, it looks like you want to create a margin report..
The following macro assumes the internal margin is in Cost B. The Cost to
the customer is assumed to be in Cost column and the internal cost in Cost1.
You need to create a formula in Cost2 to calculate the difference. Run this
macro with a Gantt chart active.

'Set Rate B for every Assignment
    For Each Tsk In ActiveProject.Tasks
        If Not Tsk Is Nothing Then
            For Each A In Tsk.Assignments
                A.Number1 = A.CostRateTable
                A.CostRateTable = 1 '1=Rate B
            Next A

        'Copy new Cost to Cost1
            Tsk.Cost1 = Tsk.Cost
        End If
    Next Tsk

'Reset Rate A as rate for every Assignment
    For Each Tsk In ActiveProject.Tasks
        If Not Tsk Is Nothing Then
            For Each A In Tsk.Assignments
                A.CostRateTable = A.Number1
            Next A
        End If
    Next Tsk

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:http://www.projectvbabook.com








- Show quoted text -

Thanks Rod,

Not exactly what i was looking for but thanks. It very difficult to
give all the details. If one could see the schedule it would help.

Andre
 

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

Similar Threads


Top