VBA Macro for Enterprise Global

S

S

Hello
I have written a macro, by first recording it, and then editing it. And i am
able to run the macro from Project Professional, but i dont know how do i
call the macro function in a Project Event(BeforeSave). Can some one help me
with the syntax and procedure for doing this.

Thanks and Regards,
S
 
R

Rod Gill

If you macro is called MyMacro,
simply enter the line
MyMacro in the event and the code runs. Is that what you needed to know?
 
S

S

Thanks Rod for the reply...

It works..
I have an another issue:
Backgroud:
I have written the below code in the Before_Save event in the enterprise
global, to perform the updation of %complete field upon saving the active
project plan.

Code is as follows:

Private Sub Project_BeforeSave(ByVal pj As Project)

Dim T As Task
Dim Temp As Long, A As Assignment
Dim aCount As Long
Dim ts As Tasks

If (pj <> Null) And (pj.Name <> "Checked-Out Enterprise Global") Then

If pj.Tasks.Count <> 0 Then
For Temp = 1 To pj.Tasks.Count
Set T = pj.Tasks(Temp)
If T.Assignments.Count <> 0 Then

For aCount = 1 To T.Assignments.Count
Set A = T.Assignments(aCount)
If T.EnterpriseText2 = "Completed" Then

pj.Tasks(Temp).Assignments(aCount).PercentWorkComplete = Val("100")
Else
If T.EnterpriseText2 = "Work In Progress" Then

pj.Tasks(Temp).Assignments(aCount).PercentWorkComplete = Val("50")
Else

pj.Tasks(Temp).Assignments(aCount).PercentWorkComplete = Val("0")
End If

End If

Next aCount

End If
Next Temp
End If
End IF

End Sub

Problem:
When i open project and view code, the code and event is not seem to be
inherited, there is no code on the Project's code window.
When i save the project nothing is happening as there is no code on the
before_save of the project. And when i am trying to close Ms Project the code
seem to get executed and gives the error
'Runtime error '91''
Object variable or with block variable is not set'
i suspect the event is firing not before save but probably on application
close event or similar.

I dont know where i am going wrong
I would be very thankful if you could help me with the above.

Thanks and Regards,
S
 
R

Rod Gill

I would write it as :

Dim Tsk As Task
Dim A As Assignment
If (pj.Name <> "Checked-Out Enterprise Global") Then
If pj.Tasks.Count > 0 Then
For Each Tsk In pj.Tasks
If Not Tsk Is Nothing Then
For Each A In Tsk.Assignments
If Tsk.EnterpriseText2 = "Completed" Then
A.PercentWorkComplete = 100
ElseIf Tsk.EnterpriseText2 = "Work In Progress" Then
A.PercentWorkComplete = 50
Else
A.PercentWorkComplete = 0
End If
Next
End If
Next
End If
End If
End Sub


Note that you got the test for Tasks.Count wrong, it should be > not <. That
may explain why your code didn't do anything. I haven't tested this code,
but it should work!!
 

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