2017-06-21 45 views
1

目標時:我想保存Change事件發生時,所有任務的UniqueIDText5值之前。運行時錯誤1100試圖在ProjApp_ProjectBeforeTaskChange「全選」(類模塊內)

因此,我有一個Class模塊clsTskUpdate,我嘗試將所有這些值保存在DictionaryProjApp_ProjectBeforeTaskChange事件中。

然而,因爲我有一個主項目和幾個子項目,我需要SelectAll任務,並通過ActiveSelection.Tasks循環得到他們UniqueID碩士項目內(感謝@Rachel的Hettinger的幫助)。

的問題開始,每當我從組合框修改ActualFinish值(如圖所示的屏幕截圖如下圖):

enter image description here

我得到一個運行時錯誤「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 
+0

如何處理保存的Text5值? –

回答

2

如果您正在尋找只保存Text5價值的任務之前被改變(任何字段),那麼試試這個:

Private Sub ProjApp_ProjectBeforeTaskChange(ByVal tsk As Task, ByVal Field As PjField, _ 
    ByVal NewVal As Variant, Cancel As Boolean) 

    If Not dict.Exists(tsk.UniqueID) Then 
     dict.Add tsk.UniqueID, tsk.Text5 
    Else 
     dict(tsk.UniqueID) = tsk.Text5 
    End If 

End Sub 

tsk.UniqueID將主項目中的獨特價值(例如8388611,而不是3)。

+0

繼我們以前的帖子(你已經幫忙解決)之後,我需要循環選擇。並且我不能在我的屏幕截圖(在我的文章)中共享的模式中使用'SelectAll',我沒有問題將值保存到字典中 –

+0

在不同的時間保存所有值 - 不是Change事件 - 可能在項目打開時。此外,無法在Excel中禁用Project中的事件,因此請小心不要在Change事件代碼中觸發其他事件。 –

相關問題