Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS project: how to reference the active file name in code?

Status
Not open for further replies.

AppStaff

Programmer
Sep 21, 2002
146
US
Below is code i found by MS that writes any entries in text1 for tasks to text 1 for resources and assignments.
What I need to do now is figure out how to set text1 for tasks = to the current active projects filename. For example a project file will be saved as a project reference number "CR0295". I would want it to loop through all the tasks in the project and first write this value (the file name minus the extension) in text1 and then run the code to update text 1 in resources and assignments. I've searched help and can't find a way to reference the active file name. I'm sure I'm probably looking in the wrong place but any help with this code is appreciated.

Sub UpdateAssignmentNumber()
'Variables for tracking current task and assignment

Dim oTask As Task

Dim oAssignment As Assignment

Dim oResource As Resource

'Looping through all tasks in the project

For Each oTask In ActiveProject.Tasks

'Checking to see if task is blank

If Not oTask Is Nothing Then

'Looping through each assignment for a task

For Each oResource In oTask.Resources
'Updating the number1 field for the assignment based on value
'at task level for the number1 field

oResource.Text1 = oTask.Text1
'Processing next assignment for the task


Next oResource

End If
If Not oTask Is Nothing Then

'Looping through each assignment for a task

For Each oAssignment In oTask.Assignments
'Updating the number1 field for the assignment based on value
'at task level for the number1 field

oAssignment.Text1 = oTask.Text1

Next oAssignment

End If

'Processing next task

Next oTask

End Sub
 
Never Mind I found it: ActiveProject.FullName is the reference. Here's the draft code to do this if anyones interested. There's stuff specific to my needs that will definitely need tweaking if anyone else uses it.

Sub FillDownCREAP()
Dim T As Task, R As Resource, A As Assignment, strEAP As String

strEAP = InputBox("Please Type EAP Number of this Project", "EAP INPUT")

For Each T In ActiveProject.Tasks
T.Text2 = Mid(ActiveProject.FullName, Len(ActiveProject.FullName) - 10, 6)
T.Text3 = strEAP
Next T


'Looping through all tasks in the project

For Each T In ActiveProject.Tasks

'Checking to see if task is blank

If Not T Is Nothing Then

'Looping through each assignment for a task

For Each A In T.Assignments

'Updating the number1 field for the assignment based on value
'at task level for the number1 field

A.Text1 = T.Text1
A.Text2 = T.Text2
A.Text3 = T.Text3

'Processing next assignment for the task

Next A

End If

If Not T Is Nothing Then

'Looping through each resource for a task

For Each R In T.Resources

'Updating the number1 field for the assignment based on value
'at task level for the number1 field

R.Text1 = T.Text1
R.Text2 = T.Text2
R.Text3 = T.Text3

'Processing next assignment for the task

Next R

End If

'Processing next task

Next T

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top