Hiding all but one column

B

bstobart

I'd like to loop through all the columns in the current view and hide all but
one. I've made some progress, but got stuck with the ColumnDelete method
because it seems to require that I know the name (or Title) of the columns.
I haven't been able to figure out the names of the columns.

Here's what I have so far:

Dim fld As TableField

For Each fld In
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields

If ([field is not field-to-keep] then
SelectTaskColumn Column:=????
ColumnDelete
End If
Next

My ultimate objective is to rebuild the default view whenever a user first
opens the project file, such that the default view always appears the same.
Reinserting the columns after removing them all, seems fairly straightforward
using a set of commands like the following:

ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields.Add _
Field:=pjTaskActualFinish, _
AlignData:=pjRight, _
Width:=10, _
Title:="Titlename", _
AlignTitle:=pjRight, _
Before:=0, _
AutoWrap:=True

So my questions are:

a) How do I determine the appropriate column name such that I can use the
SelectColumn command?
b) Is there a better option for resetting a view to a standard (removing all
non-standard columns, resetting all widths to standard widths, turning off
filtering etc)
 
J

Jack Dahlgren

I agree with Jan. Use the table edit method and create the table from
scratch every time.
You can reuse the table name and just overwrite the existing table
definition.
Use the macro recorder to ease writing the code.

-Jack


Jan De Messemaeker said:
Hi,

There definitely is a better view: the TableEdit method.
Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
bstobart said:
I'd like to loop through all the columns in the current view and hide all
but
one. I've made some progress, but got stuck with the ColumnDelete method
because it seems to require that I know the name (or Title) of the
columns.
I haven't been able to figure out the names of the columns.

Here's what I have so far:

Dim fld As TableField

For Each fld In
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields

If ([field is not field-to-keep] then
SelectTaskColumn Column:=????
ColumnDelete
End If
Next

My ultimate objective is to rebuild the default view whenever a user
first
opens the project file, such that the default view always appears the
same.
Reinserting the columns after removing them all, seems fairly
straightforward
using a set of commands like the following:

ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields.Add _
Field:=pjTaskActualFinish, _
AlignData:=pjRight, _
Width:=10, _
Title:="Titlename", _
AlignTitle:=pjRight, _
Before:=0, _
AutoWrap:=True

So my questions are:

a) How do I determine the appropriate column name such that I can use the
SelectColumn command?
b) Is there a better option for resetting a view to a standard (removing
all
non-standard columns, resetting all widths to standard widths, turning
off
filtering etc)
 
B

bstobart

Thanks. This worked perfectly. My intention was actually not to just hide
all columns but rather to reset the view to its default settings.

One note: The first time I recorded the creation of a new view, the
resulting macro did not use TableEdit. I think that's because I created a
new view, rather than a new table. I have to admit that I haven't quite
figured out the difference, but the view characteristics I want to update are
stored at the table level. Once I created a new table using:
View->Table:Entry->More Tables->New, the resulting recorded macro gave me the
desired results (using TableEdit).

For anyone who may be interested, I'm including the text of the resulting
macro below. This macro can now run every time the project is opened (by
inserting it in the OpenProject event method) such that the columns are
always reset back to the defaults. In other words it overwrites the previous
settings, so it doesn't error out if the table already exists. A couple of
my columns are custom, but the whole macro should work for anyone. The macro
below is exactly as it was recorded, except for a few column widths, so there
may be some unnecessary options.

---------------------------

Sub ResetEntryTable()

' This macro resets the "Entry" table to its default settings. This
includes which columns are displayed,
' their order and widths. The Entry table is used by some of the main
views, including the Gantt chart view.

TableEdit Name:="Entry", TaskTable:=True, Create:=True,
OverwriteExisting:=True, FieldName:="ID", Title:="", Width:=6, Align:=1,
ShowInMenu:=False, LockFirstColumn:=True, DateFormat:=255, RowHeight:=1,
AlignTitle:=1

TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text9",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Unique ID",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Name",
Title:="", Width:=40, Align:=0, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text8",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Predecessors",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Successors",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text7",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text30",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Cost",
Title:="", Width:=15, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Cost",
Title:="", Width:=15, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="% Work
Complete", Title:="", Width:=10, Align:=2, LockFirstColumn:=True,
DateFormat:=255, RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Duration",
Title:="", Width:=10, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Work",
Title:="", Width:=12, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Work",
Title:="", Width:=12, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Start",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Start",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Finish",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Finish",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Resource
Names", Title:="", Width:=20, Align:=2, LockFirstColumn:=True,
DateFormat:=255, RowHeight:=1, AlignTitle:=1

TableApply Name:="Entry"

End Sub

---------------------------

Jack Dahlgren said:
I agree with Jan. Use the table edit method and create the table from
scratch every time.
You can reuse the table name and just overwrite the existing table
definition.
Use the macro recorder to ease writing the code.

-Jack


Jan De Messemaeker said:
Hi,

There definitely is a better view: the TableEdit method.
Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
bstobart said:
I'd like to loop through all the columns in the current view and hide all
but
one. I've made some progress, but got stuck with the ColumnDelete method
because it seems to require that I know the name (or Title) of the
columns.
I haven't been able to figure out the names of the columns.

Here's what I have so far:

Dim fld As TableField

For Each fld In
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields

If ([field is not field-to-keep] then
SelectTaskColumn Column:=????
ColumnDelete
End If
Next

My ultimate objective is to rebuild the default view whenever a user
first
opens the project file, such that the default view always appears the
same.
Reinserting the columns after removing them all, seems fairly
straightforward
using a set of commands like the following:

ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields.Add _
Field:=pjTaskActualFinish, _
AlignData:=pjRight, _
Width:=10, _
Title:="Titlename", _
AlignTitle:=pjRight, _
Before:=0, _
AutoWrap:=True

So my questions are:

a) How do I determine the appropriate column name such that I can use the
SelectColumn command?
b) Is there a better option for resetting a view to a standard (removing
all
non-standard columns, resetting all widths to standard widths, turning
off
filtering etc)
 
R

Rod Gill

There is a simpler way of restoring defaults: In the auto open macro, delete
all Views and Tables in the active project so that next time they are viewed
they will be copied fresh from the Global.Mpt file. you will need to swap
Views around to be able to delete the last, active View.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com



bstobart said:
Thanks. This worked perfectly. My intention was actually not to just
hide
all columns but rather to reset the view to its default settings.

One note: The first time I recorded the creation of a new view, the
resulting macro did not use TableEdit. I think that's because I created a
new view, rather than a new table. I have to admit that I haven't quite
figured out the difference, but the view characteristics I want to update
are
stored at the table level. Once I created a new table using:
View->Table:Entry->More Tables->New, the resulting recorded macro gave me
the
desired results (using TableEdit).

For anyone who may be interested, I'm including the text of the resulting
macro below. This macro can now run every time the project is opened (by
inserting it in the OpenProject event method) such that the columns are
always reset back to the defaults. In other words it overwrites the
previous
settings, so it doesn't error out if the table already exists. A couple
of
my columns are custom, but the whole macro should work for anyone. The
macro
below is exactly as it was recorded, except for a few column widths, so
there
may be some unnecessary options.

---------------------------

Sub ResetEntryTable()

' This macro resets the "Entry" table to its default settings. This
includes which columns are displayed,
' their order and widths. The Entry table is used by some of the main
views, including the Gantt chart view.

TableEdit Name:="Entry", TaskTable:=True, Create:=True,
OverwriteExisting:=True, FieldName:="ID", Title:="", Width:=6, Align:=1,
ShowInMenu:=False, LockFirstColumn:=True, DateFormat:=255, RowHeight:=1,
AlignTitle:=1

TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text9",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Unique ID",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Name",
Title:="", Width:=40, Align:=0, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text8",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Predecessors",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Successors",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text7",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Text30",
Title:="", Width:=3, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Cost",
Title:="", Width:=15, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Cost",
Title:="", Width:=15, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="% Work
Complete", Title:="", Width:=10, Align:=2, LockFirstColumn:=True,
DateFormat:=255, RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Duration",
Title:="", Width:=10, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Work",
Title:="", Width:=12, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Work",
Title:="", Width:=12, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual Start",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Start",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Finish",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Actual
Finish",
Title:="", Width:=11, Align:=2, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, AlignTitle:=1
TableEdit Name:="Entry", TaskTable:=True, NewFieldName:="Resource
Names", Title:="", Width:=20, Align:=2, LockFirstColumn:=True,
DateFormat:=255, RowHeight:=1, AlignTitle:=1

TableApply Name:="Entry"

End Sub

---------------------------

Jack Dahlgren said:
I agree with Jan. Use the table edit method and create the table from
scratch every time.
You can reuse the table name and just overwrite the existing table
definition.
Use the macro recorder to ease writing the code.

-Jack


Jan De Messemaeker said:
Hi,

There definitely is a better view: the TableEdit method.
Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
I'd like to loop through all the columns in the current view and hide
all
but
one. I've made some progress, but got stuck with the ColumnDelete
method
because it seems to require that I know the name (or Title) of the
columns.
I haven't been able to figure out the names of the columns.

Here's what I have so far:

Dim fld As TableField

For Each fld In
ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields

If ([field is not field-to-keep] then
SelectTaskColumn Column:=????
ColumnDelete
End If
Next

My ultimate objective is to rebuild the default view whenever a user
first
opens the project file, such that the default view always appears the
same.
Reinserting the columns after removing them all, seems fairly
straightforward
using a set of commands like the following:


ActiveProject.TaskTables(ActiveProject.CurrentTable).TableFields.Add _
Field:=pjTaskActualFinish, _
AlignData:=pjRight, _
Width:=10, _
Title:="Titlename", _
AlignTitle:=pjRight, _
Before:=0, _
AutoWrap:=True

So my questions are:

a) How do I determine the appropriate column name such that I can use
the
SelectColumn command?
b) Is there a better option for resetting a view to a standard
(removing
all
non-standard columns, resetting all widths to standard widths, turning
off
filtering etc)
 

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