前綴:我正在運行代碼,根據Text1
字段中的值更改任務行的格式。在MS-Project 2007中的FormatTask之後無法使用「撤消」宏運行
所以,如果我改變Duration
,或Finish
或當我更新時間表一些其它值,Text1
(定製字段)的值被modied爲好。作爲該值的結果,我正在格式化背景顏色和字體顏色。
問題:一旦我運行此代碼,我不能使用常規的「撤消」,並且我無法讓值返回到更新前的先前狀態。
任何幫助如何創建「自定義撤消」高度讚賞。
ThisProject代碼
Private Sub Project_Change(ByVal pj As Project)
' enable class to modify the Task format on Project change (when a task is changed)
StatusRYGFieldUpdate
End Sub
常規代碼模塊
Option Explicit
Public StatusRYGView As New clsTskUpdate
Public UpdateViewFlag As Boolean
Public TskIDChanged As Long
Sub StatusRYGFieldUpdate()
' this Sub is triggered once a task is modified
' if the Field being modifed is related to "Text1"
Dim CurTskID As Long
Set StatusRYGView.ProjApp = Application
Application.Calculation = pjManual
Application.ScreenUpdating = False
If UpdateViewFlag Then
CurTskID = TskIDChanged ' save Row ID
FormatTask (TskIDChanged) ' call the Sub that formats the cell (send the taskId)
End If
Application.Calculation = pjAutomatic
Application.ScreenUpdating = False
End Sub
'===========================================================
Sub FormatTask(TskID)
Dim Tsk As Task
If UpdateViewFlag Then
SelectTaskField TskID, "Text1", False
Set Tsk = ActiveCell.Task ' set the Task to current cell's Task
SelectRow Row:=TskID, RowRelative:=False
' format entire row first
Select Case Tsk.Text1 ' Get the Field's used field, not name
Case "R"
FontEx CellColor:=7, Color:=0
FontEx Italic:=False
Case "Complete"
FontEx Italic:=True
FontEx CellColor:=15, Color:=14 ' Background Silver ; font Gray
End Select
' format "Status" field
SelectTaskField TskID, "Text1", False
Select Case Tsk.Text1 ' Get the Field's used field, not name
Case "R"
' Font Color:=pjWhite ' Font White
FontEx Italic:=False
FontEx CellColor:=1, Color:=7 ' Background Red ; font White
Case "Complete"
FontEx Italic:=True ' Font Italic
FontEx CellColor:=15, Color:=14 ' Background Silver ; font Gray
End Select
End If ' UpdateViewFlag is True
End Sub
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)
' Sub (in "clsTskUpdate" Class) is triggered once a task is modified
' if the Field being modifed is related to "Text1"
' then the UpdateViewFlag is being raised, and the Tsk.ID (task's row) is saved to TskIDChanged variable
UpdateViewFlag = False
TskIDChanged = 0
Select Case Field
Case pjTaskActualFinish
If Not NewVal Like Format(Tsk.ActualFinish, myDateFormat) Then ' need to modify date format to "dd/mm/yy"
LastValue = Tsk.ActualFinish
UpdateViewFlag = True
TskIDChanged = Tsk.ID
End If
Case pjTaskStart
If Not NewVal Like Format(Tsk.Start, myDateFormat) Then ' need to modify date format to "dd/mm/yy"
LastValue = Tsk.Start
UpdateViewFlag = True
TskIDChanged = Tsk.ID
End If
Case pjTaskDuration
If Not NewVal Like (Tsk.Duration/480) & "*" Then ' need to divide by 480 (in minutes) and add `*` wild-card for "days"
LastValue = Tsk.Duration/480
UpdateViewFlag = True
TskIDChanged = Tsk.ID
End If
Case pjTaskPercentComplete
If Not NewVal Like Tsk.PercentComplete Then
LastValue = Tsk.PercentComplete
UpdateViewFlag = True
TskIDChanged = Tsk.ID
End If
' other possible Case Scenarios in the future
End Select
End Sub
請說明您是通過更新的問題標題中使用其MS Project版本。 –
@RachelHettinger它是2007年, –