2017-06-21 95 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事件代码中触发其他事件。 –

相关问题