在MS Project中使用替换VBA功能

时间:2019-01-22 04:14:01

标签: vba ms-project

我正在尝试找出如何在MS Project中应用替换功能。我已经看过https://docs.microsoft.com/en-us/office/vba/api/project.application.replace上的资料,但仍然无法正常工作。

以下代码与一个问题有关,该问题是我使用MS Project安排培训课程(这些是“任务”)并将用户(资源)添加到这些课程(任务)的问题。其中一些用户必须出差,因此我创建了一个自定义字段,以便能够跟踪必须参加一次会议的人数及其位置。

'T.Text16 is the column for the Travel flag itself
'T.Text5 is the location of the session
'R.Text 3 is the home location of the User
Sub User_Travel_Flag()
'Identitifies the number of user locations in a session that had to travel 
to the training location
'(i.e. the home users location is not part of the total)
Dim Count As String

 If MsgBox("Have you allocated User to sessions first?", vbYesNo + 
 vbInformation, "Check User allocation") = vbNo Then Exit Sub

For Each T In ActiveProject.Tasks
    T.Text16 = ""
Next T

For Each T In ActiveProject.Tasks

Application.StatusBar = "Checking task ID " & T.ID & "...."

For Each asn In T.Assignments
    If Left(asn.ResourceName, 1) = "U" Then  'Find the User Resources

        If T.Text5 <> asn.Resource.Text3 Then 'the Training Facility is 
         different to the User's home facility
         ' print resource's initials and standard rate
            If T.Text16 = "" Then
                T.Text16 = asn.Resource.Text3 & "x1"
            ElseIf InStr(1, T.Text16, asn.Resource.Text3) = 0 Then
                T.Text16 = T.Text16 & ", " & asn.Resource.Text3 & "x1"
            Else
                Count = Mid(T.Text16, InStr(1, T.Text16, asn.Resource.Text3) + Len(asn.Resource.Text3) + 1, 1)
                'THIS REPLACE PART DOESNT WORK.  It says the field is an issue
                **Replace Field:=T.Text16, Test:="equals", Value:=asn.Resource.Text3 & " " & Count, Replacement:=asn.Resource.Text3 & " " & Count + 1, ReplaceAll:=False**

            End If
        End If
    End If
Next asn
Next T

Application.StatusBar = True

MsgBox "The flagging of the location of users that have to travel to 
training 
has been successfully completed.", vbInformation, "Complete"

End Sub

0 个答案:

没有答案