H
hale
Hi all:
I want to Use VBA to save value into Custom Enterprise Project Text1 and
Custom Enterprise Project Text1 when Project Publish.
Private Sub Project_BeforeSave(ByVal pj As Project)
Transfer_Task_Codes
End Sub
Sub Transfer_Task_Codes()
Dim tskT As Task
Dim rscR As Resource
Dim asnA As Assignment
Dim strResource As String
Dim strReqDep As String
Dim nbItems As Integer
On Error GoTo ErrorHandler
On Error Resume Next
If Application.Projects.Count > 0 Then
If ActiveProject.Tasks.Count > 0 Then
For Each tskT In ActiveProject.Tasks
If Not (tskT Is Nothing) Then
nbItems = tskT.Assignments.Count
If nbItems > 0 Then
For i = 1 To nbItems
'tskT.Assignments.Item(i).EnterpriseResourceOutlineCode28 =
tskT.EnterpriseOutlineCode1
'tskT.Assignments.Item(i).EnterpriseResourceOutlineCode29 =
tskT.EnterpriseOutlineCode2
If InStr(strReqDep,
CStr(tskT.EnterpriseOutlineCode1)) < 1 Then
If strReqDep = "" Then
strReqDep = strReqDep &
tskT.EnterpriseOutlineCode1
Else
strReqDep = strReqDep & "," &
tskT.EnterpriseOutlineCode1
End If
End If
If InStr(strResource,
CStr(tskT.Assignments.Item(i).ResourceName)) < 1 Then
If strResource = "" Then
strResource = strResource &
tskT.Assignments.Item(i).ResourceName
Else
Debug.Print strResource
strResource = strResource & "," &
tskT.Assignments.Item(i).ResourceName
End If
End If
Next i
End If
End If
Next tskT
Application.SetField pjCustomProjectEnterpriseText1, strReqDep
Application.SetField pjCustomProjectEnterpriseText2, strResource
End If
End If
Exit Sub
ErrorHandler:
MsgBox Err.Description & Chr(13) & "In Task: " & tskT.ID & Chr(13) & "In
Assignment: " & asnA.UniqueID, vbCritical, "Code Transfer Error"
Resume Next
End Sub
But I am not success.
Thank you for any help!
hale
I want to Use VBA to save value into Custom Enterprise Project Text1 and
Custom Enterprise Project Text1 when Project Publish.
Private Sub Project_BeforeSave(ByVal pj As Project)
Transfer_Task_Codes
End Sub
Sub Transfer_Task_Codes()
Dim tskT As Task
Dim rscR As Resource
Dim asnA As Assignment
Dim strResource As String
Dim strReqDep As String
Dim nbItems As Integer
On Error GoTo ErrorHandler
On Error Resume Next
If Application.Projects.Count > 0 Then
If ActiveProject.Tasks.Count > 0 Then
For Each tskT In ActiveProject.Tasks
If Not (tskT Is Nothing) Then
nbItems = tskT.Assignments.Count
If nbItems > 0 Then
For i = 1 To nbItems
'tskT.Assignments.Item(i).EnterpriseResourceOutlineCode28 =
tskT.EnterpriseOutlineCode1
'tskT.Assignments.Item(i).EnterpriseResourceOutlineCode29 =
tskT.EnterpriseOutlineCode2
If InStr(strReqDep,
CStr(tskT.EnterpriseOutlineCode1)) < 1 Then
If strReqDep = "" Then
strReqDep = strReqDep &
tskT.EnterpriseOutlineCode1
Else
strReqDep = strReqDep & "," &
tskT.EnterpriseOutlineCode1
End If
End If
If InStr(strResource,
CStr(tskT.Assignments.Item(i).ResourceName)) < 1 Then
If strResource = "" Then
strResource = strResource &
tskT.Assignments.Item(i).ResourceName
Else
Debug.Print strResource
strResource = strResource & "," &
tskT.Assignments.Item(i).ResourceName
End If
End If
Next i
End If
End If
Next tskT
Application.SetField pjCustomProjectEnterpriseText1, strReqDep
Application.SetField pjCustomProjectEnterpriseText2, strResource
End If
End If
Exit Sub
ErrorHandler:
MsgBox Err.Description & Chr(13) & "In Task: " & tskT.ID & Chr(13) & "In
Assignment: " & asnA.UniqueID, vbCritical, "Code Transfer Error"
Resume Next
End Sub
But I am not success.
Thank you for any help!
hale