FrenchCAD
Mechanical
- Feb 8, 2002
- 321
Hi all,
I wrote a VBA macro in MSP to insert a column (TaskColumn Flag20) to display specific indicator. It works well except that it creates the column each time I open the project file. Hence I am looking for a way to check if the column exists and is visible when opening file to disable macro. I couldn't find any information on such possibility.
Other solution I have in mind would be to delete column at file closure but for some reason the BeforeClose() method doesn't seem to work.
My piece of code if needed or curious:
Cyril Guichard
Space Program Manager
Belgium
I wrote a VBA macro in MSP to insert a column (TaskColumn Flag20) to display specific indicator. It works well except that it creates the column each time I open the project file. Hence I am looking for a way to check if the column exists and is visible when opening file to disable macro. I couldn't find any information on such possibility.
Other solution I have in mind would be to delete column at file closure but for some reason the BeforeClose() method doesn't seem to work.
My piece of code if needed or curious:
Code:
Attribute VB_Name = "FlagTasksToUpdate"
Public Sub Auto_Open()
TasksToUpdate
End Sub
Private Sub Project_BeforeClose(ByVal pj As Project)
SelectTaskColumn Column:="Flag20"
ColumnDelete
'FileCloseEx pjSave
End Sub
Public Sub TasksToUpdate()
'Activate Gantt Chart view
ActiveProject.Application.ViewApply "Tracking Gantt"
ZoomTimescale Entire:=True
PaneClose
SelectTaskColumn Column:="Name"
OutlineShowAllTasks
'Insert new column Flag20 in second position and rename it Need Update
TableEditEx Name:="Entry", TaskTable:=True, Create:=False, NewName:="", NewFieldName:="Flag20", Width:=8, ShowInMenu:=True, _
LockFirstColumn:=True, OverwriteExisting:=False, Title:="Need Update", ColumnPosition:=1
TableApply "Entry"
'Add formula to chake if task needs update
'i.e. if (current date is higher than task start date AND % complete is null) [Late Start] OR (current date is higher than task finish date AND % complete is not 100%) [Late Finish]
CustomFieldSetFormula FieldID:=pjCustomTaskFlag20, Formula:="IIf((Date()>[Start] And [% Complete]=0) Or (Date()>[Finish] And [% Complete]<>100),True,False)"
CustomFieldIndicators FieldID:=pjCustomTaskFlag20, SummaryInheritsNonsummary:=True, ProjectInheritsSummary:=True, ShowToolTips:=True
'If task needs update then display red square on line
CustomFieldIndicatorAdd FieldID:=pjCustomTaskFlag20, Test:=pjCompareEquals, Value:="Yes", IndicatorID:=pjIndicatorSquareRed
'If not, display green square
CustomFieldIndicatorAdd FieldID:=pjCustomTaskFlag20, Test:=pjCompareEquals, Value:="No", IndicatorID:=pjIndicatorSquareLime
CustomFieldPropertiesEx FieldID:=pjCustomTaskFlag20, Attribute:=pjFieldAttributeFormula, SummaryCalc:=pjCalcNone, GraphicalIndicators:=True
End Sub
Cyril Guichard
Space Program Manager
Belgium