Where do I enter VBA Code? Project 2007

W

Wendy

I am not a developer so I need help understanding where to put this code. We
need for the % complete to show with decimals and I found this code in this
forum but I don't know where to put it. Does it go in a macro and if so
under what event?
Or does it go in the formula for a custom enterprise text field under the
formula button? I tried putting it in the custom field but I got errors
saying syntax, unrecognized formula or function name. Please help. Here is
exactly what I inserted: Thanks

Private Sub Project_Change(ByVal pj As Project)

Dim t As Task

For Each t In ActiveProject.Tasks
If Not (t Is Nothing) Then
t.Text1 = Format((t.ActualDuration / t.Duration), "0.0000%")
End If
Next t

End Sub
 
J

Jim Aksel

Tools/Macros/Visual Basic Editor.
Or, use Alt+F11

In the window that opens, click Insert/Module...
Paste code into the right window.

There will be a problem...
Change the first line from
Private Sub Project_Change( ....
to
Public Sub Project_Change(....

Making it public lets you run it from the Macro section, otherwise you have
to run it from the VBA Editor.

To run the code, if you are in the Visual Basic Editor, you can select
anywhere in the code and press the "run" button, it looks like a blue right
arrow.

From within the Project file itself, Tools/Macros/Macro...
Look for the name Change_Project

Hope that helps.


--
If this post was helpful, please consider rating it.

Jim
It''s software; it''s not allowed to win.

Visit http://project.mvps.org/ for FAQs and more information
about Microsoft Project
 
J

Jack Dahlgren

That code runs on the project change event.
You can read about them here:
http://zo-d.com/blog/archives/programming/working-with-microsoft-project-events-on-open.html

An easier way would be to put a similar function in a custom field. The
following should work if you use it as a formula in a text field.:

Format(([Actual Duration]/[Duration]),"0.0000%")

However, the number of decimal places is absurd. The final decimal place on
a day long task represents a bit more than 1/100th of a second. On a year
long task it would represent 7 seconds.

Why not just insert the %Complete column and be done with it?

-Jack Dahlgren
http://zo-d.com/blog
 

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