×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to check via VBA if a custom column exists in tasks view?

how to check via VBA if a custom column exists in tasks view?

how to check via VBA if a custom column exists in tasks view?

(OP)
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:

CODE --> project-vba

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close