我目前的代码如下:我输入一个UID,然后一个消息框显示任务的松弛。但是,在消息框打开时,无法编辑Microsoft Project文件。
我可以在VBA中使用另一个对象来显示相同的输出但允许我在输出输出时处理项目文件吗?并且,是否可以实时输出?换句话说,如果我在我的日程安排中进行更改,如果松弛发生变化,我可以看到输出不断变化,而不必再次运行应用程序吗?
Sub SlackFinder()
Dim User_UID, User_ID As Integer
Dim Slack As Variant
Dim NewSlack As Variant
User_UID = InputBox("Enter UID for slack:")
If User_UID = "" Then Exit Sub
On Error GoTo Error_Not_Found
User_ID = ActiveProject.Tasks.UniqueID(User_UID).ID
On Error GoTo Error_Collapsed
Slack = ActiveProject.Tasks.UniqueID(User_UID).TotalSlack
NewSlack = Slack / 480
MsgBox "Total Slack: " & NewSlack
Exit Sub
Error_Not_Found:
MsgBox "UID " & User_UID & " not found in " & ActiveProject.Name
Exit Sub
Error_Collapsed:
MsgBox "UID is present but cannot be selected. Perhaps it is collapsed?", vbOKOnly, "COLLAPSED UID?"
Exit Sub
End Sub
答案 0 :(得分:0)
您可以使用无模式用户表单显示实时松弛。在VBA中创建用户表单,例如具有用于输入任务UID的文本框和用于显示总松弛值的标签:
然后将此代码添加到UserForm模块:
Private Sub UID_Change()
UpdateTotalSlack
End Sub
Sub UpdateTotalSlack()
On Error Resume Next
Me.TSlack = "Total Slack = " & ActiveProject.Tasks.UniqueID(Me.UID).TotalSlack / 480
End Sub
将其添加到项目模块:
Sub ShowSlack()
UserForm1.Show False
End Sub
Private Sub Project_Change(ByVal pj As Project)
UserForm1.UpdateTotalSlack
End Sub
首先,调用ShowSlack
程序。这将无模式显示用户表单(例如,它浮动在MS Project窗口上方,允许您对计划进行更改)。在文本框中输入任务UID,并且只要对计划进行更改,就会立即显示Total Slack并更新(感谢Change事件代码)。
答案 1 :(得分:0)
项目模块:
Private Sub Project_Change(ByVal pj As Project)
MsgBox "hi"
UserForm10.UpdateTotalSlack
End Sub
第29单元:
Sub ShowSlack()
UserForm10.Show False
End Sub
Userform10:
Dim User_UID As Variant
Dim TSlack As Variant
Private Sub TextBox3_Change()
User_UID = UserForm10.TextBox3.Value
UpdateTotalSlack
End Sub
Sub UpdateTotalSlack()
On Error Resume Next
If Not User_UID = "" Then
TSlack = ActiveProject.Tasks.UniqueID(User_UID).TotalSlack / 480
Else
TSlack = ""
End If
UserForm10.Label1.Caption = TSlack
End Sub