目標時:我想保存Change
事件發生時,所有任務的UniqueID
和Text5
值之前。運行時錯誤1100試圖在ProjApp_ProjectBeforeTaskChange「全選」(類模塊內)
因此,我有一個Class模塊clsTskUpdate
,我嘗試將所有這些值保存在Dictionary
的ProjApp_ProjectBeforeTaskChange
事件中。
然而,因爲我有一個主項目和幾個子項目,我需要SelectAll
任務,並通過ActiveSelection.Tasks
循環得到他們UniqueID
碩士項目內(感謝@Rachel的Hettinger的幫助)。
的問題開始,每當我從組合框修改ActualFinish
值(如圖所示的屏幕截圖如下圖):
我得到一個運行時錯誤「1100 「:
的方法是不是在這種情況下
在下面的林可e(Sub ProjApp_ProjectBeforeTaskChange
)
SelectAll
有沒有人在這裏知道如何處理它?我如何在任務更新之前使用SelectAll
來保存我的Dictionary
中的所有當前值?
類clsTskUpdate代碼
Option Explicit
Public WithEvents ProjApp As Application
Private Sub ProjApp_ProjectBeforeTaskChange(ByVal Tsk As Task, ByVal Field As PjField, ByVal NewVal As Variant, Cancel As Boolean)
RowIDChanged = Tsk.UniqueID
MsgBox Application.StatusBar
SaveStatusforAllTasks ' call SaveStatusforAllTasks Sub, which saves current status of Text5 ("Status") of all tasks
End Sub
'===================================================================
Sub SaveStatusforAllTasks()
Dim AllTasks As Tasks
Dim Tsk As Task
' ****** Get Error 1100 at the line below *****
SelectAll
Set AllTasks = ActiveSelection.Tasks
' add existing values of UniqueID and Text5 to Dictionary object
Set Dict = CreateObject("Scripting.Dictionary")
For Each Tsk In AllTasks
If Not Tsk Is Nothing Then
If Not Dict.exists(Tsk.UniqueID) Then
Dict.Add Tsk.UniqueID, Tsk.Text5
End If
End If
Next Tsk
End Sub
該項目代碼
Private Sub Project_Change(ByVal pj As Project)
StatusRYGFieldUpdate
End Sub
普通模塊代碼
Option Explicit
Public StatusRYGView As New clsTskUpdate
Public RowIDChanged As Long
Public Const myDateFormat As String = "dd/mm/yy"
Public Dict As Object ' use a Dictionary to save previous values of all UniqueID and Text5 values ("Status")
Sub StatusRYGFieldUpdate()
Set StatusRYGView.ProjApp = Application
PaneClose ' should close the Split window (to make sure run-time error 1100 won't happen
Application.Calculation = pjManual
Application.ScreenUpdating = False
If UpdateViewFlag Then
FormatModifiedTasks ' call FormatModifiedTasks Sub, which updates all tasks that Text5 ("Status") were modified
End If
Application.Calculation = pjAutomatic
Application.ScreenUpdating = True
End Sub
如何處理保存的Text5值? –