J
jennifer.lyon
VBA newbie here... self-taught by reading code and playing around with
little snippets.
Trying to make a little bit of VBA code/macro that will run when a
series of Project files are opened, to check if certain columns are
visible on the Task Entry view, and if not, display them.
So first I made 2 little subs (one for each column) that uses very
elementary error handling after attempting to select the column in
question (eventually I'll redo this to avoid the "GoTo"). An example
of one of the subs is below...the other sub is identical except for the
name of the label, and name of the column (which is "Text2" with title
renamed to "Contractor")
Sub ShowPredecessors()
On Error GoTo ShowPredecessorColumn
SelectTaskColumn Column:="Predecessors"
MsgBox "Predecessors Column Already There"
Exit Sub
ShowPredecessorColumn:
SelectTaskColumn Column:="Resource Names"
TableEdit Name:="&Entry", TaskTable:=True, NewName:="",
FieldName:="", _
NewFieldName:="Predecessors", Title:="", Width:=10,
Align:=2, _
ShowInMenu:=True, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, _
ColumnPosition:=6, AlignTitle:=1
TableApply Name:="&Entry"
MsgBox "Added Predecessors Column"
End Sub
Okay... as stand-alone subs, running from the VB editor, they worked
fine.
Went to follow the suggestion for an Autorun, and created the following
in the "Microsoft Project Objects" tab of my GLOBAL.MPT
Private Sub Project_Open(ByVal pj As Project)
ShowPredecessors
ShowContractor
End Sub
In all cases, the MsgBox calls are for validation/checking only without
using the watch/debug window.
Now... when I open the Project file, it appears the code gets run
twice. If the columns are already showing, I get the message box that
the Predecessors Column is already there, then a message box that the
Contractor column is already there, then ANOTHER message box that the
Predecessors column is already there, and a final message box for the
Contractor column.
It seems to me that both subs are being called first from the
Project_Open sub in the GLOBAL.MPT and then each individually from
their definition in the Modules section of the GLOBAL.MPT.
Is this correct?
I would like the routines to run once and once only when the file is
open. If one or both columns aren't showing, then show them. If
they're showing, then nothing else needs to happen.
Suggestions for improvement and stupid comments gladly accepted in this
case. Like I said, I self-taught myself the VBA in these routines
today as I worked on them.
--jennifer
little snippets.
Trying to make a little bit of VBA code/macro that will run when a
series of Project files are opened, to check if certain columns are
visible on the Task Entry view, and if not, display them.
So first I made 2 little subs (one for each column) that uses very
elementary error handling after attempting to select the column in
question (eventually I'll redo this to avoid the "GoTo"). An example
of one of the subs is below...the other sub is identical except for the
name of the label, and name of the column (which is "Text2" with title
renamed to "Contractor")
Sub ShowPredecessors()
On Error GoTo ShowPredecessorColumn
SelectTaskColumn Column:="Predecessors"
MsgBox "Predecessors Column Already There"
Exit Sub
ShowPredecessorColumn:
SelectTaskColumn Column:="Resource Names"
TableEdit Name:="&Entry", TaskTable:=True, NewName:="",
FieldName:="", _
NewFieldName:="Predecessors", Title:="", Width:=10,
Align:=2, _
ShowInMenu:=True, LockFirstColumn:=True, DateFormat:=255,
RowHeight:=1, _
ColumnPosition:=6, AlignTitle:=1
TableApply Name:="&Entry"
MsgBox "Added Predecessors Column"
End Sub
Okay... as stand-alone subs, running from the VB editor, they worked
fine.
Went to follow the suggestion for an Autorun, and created the following
in the "Microsoft Project Objects" tab of my GLOBAL.MPT
Private Sub Project_Open(ByVal pj As Project)
ShowPredecessors
ShowContractor
End Sub
In all cases, the MsgBox calls are for validation/checking only without
using the watch/debug window.
Now... when I open the Project file, it appears the code gets run
twice. If the columns are already showing, I get the message box that
the Predecessors Column is already there, then a message box that the
Contractor column is already there, then ANOTHER message box that the
Predecessors column is already there, and a final message box for the
Contractor column.
It seems to me that both subs are being called first from the
Project_Open sub in the GLOBAL.MPT and then each individually from
their definition in the Modules section of the GLOBAL.MPT.
Is this correct?
I would like the routines to run once and once only when the file is
open. If one or both columns aren't showing, then show them. If
they're showing, then nothing else needs to happen.
Suggestions for improvement and stupid comments gladly accepted in this
case. Like I said, I self-taught myself the VBA in these routines
today as I worked on them.
--jennifer