Macro to display a default project view

S

Steve in Boston

I am new to MS Project VBA macros. I have set up a couple of buttons to
display various views into the project. One is called "Default View", which
will restore the project to a standard view that we use a lot. The button
and view works, but since I am new to VBA, I'm not sure if it is as efficient
as it could be, so I thought I would post it here for comment. Thank you.

Notes: The first IF statement is because I only want it to execute
button/macro for my project, or else I can't guarantee the filter and table
will be there and the macro will break. At the end, I compress the project
down level by level to Outline=2 so that when the user expands the project,
only one level at a time is expanded. Finally, I force the active cell to
the top row, second column. Any better ways to do any of this would be
appreciated.

Sub DefaultView()
' This routine restores the project view to the default view
If ActiveProject.Tasks(1).Name = "XYZ Project" Then
OutlineShowAllTasks
ViewApply Name:="Task Sheet"
TableApply Name:="_My_Default"
FilterApply Name:="All Tasks", Highlight:=False
OutlineShowTasks 5
OutlineShowTasks 4
OutlineShowTasks 3
OutlineShowTasks 2
SelectBeginning
SelectCellRight
End If
End Sub
 
J

Jack Dahlgren

To make it a bit more robust I'd build the table from scratch (record a
macro of building the table to get the code for that), then build the view,
then apply the view. This may take a bit more code, but it will work on any
project and the code should be so fast that you won't be able to tell the
difference between the two.

The "All Tasks" filter is part of the global.mpt file so I think it should
always be there.

-Jack Dahlgren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top