You are on page 1of 14

Sub Auto_Open() Dim cbar As CommandBar Dim cbtl As CommandBarButton Application.ScreenUpdating = False On Error Resume Next Application.CommandBars("Utiles").

Delete Set cbar = Application.CommandBars.Add("Utiles", msoBarTop, False, True) cbar.Visible = True Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 292 .Caption = "Previo" .TooltipText = "Formato para Agregar las tres revisiones" .OnAction = "FormatoActividad" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 1049 .Caption = "Revisiones" .TooltipText = "Incluye las tres revisiones" .OnAction = "Actividades" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 326 .Caption = "Ingeniero" .TooltipText = "Agrega al Ingeniero como recurso" .OnAction = "Ingeniero" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 326 .Caption = "Tecnico" .TooltipText = "Agrega al Tecnico como recurso" .OnAction = "Tecnico" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 327 .Caption = "Ing+Tec" .TooltipText = "Agrega al Ingeniero y el Tecnico como recurso" .OnAction = "IngTec" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 602

.Caption = "Resaltar" .TooltipText = "Resalta actividades por descripcion" .OnAction = "FiltroDescripcion" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 605 .Caption = "Trace" .TooltipText = "Resalta actividades por dependencias" .OnAction = "Trace" .Style = msoButtonIconAndCaptionBelow End With Set cbctl = Application.CommandBars("Utiles").Controls.Add(msoControlButton) With cbctl .FaceId = 606 .Caption = "Sin Filtro" .TooltipText = "Quita los Filtros" .OnAction = "SinFiltro" .Style = msoButtonIconAndCaptionBelow End With End Sub Sub Auto_Close() Application.ScreenUpdating = False On Error Resume Next Application.CommandBars("Utiles").Delete End Sub Sub Actividades() ' Macro Actividades ' Macro grabada el dom 10/02 por egonzalez. SetTaskField Field:="Nombre", Value:="Emision A" SelectTaskField Row:=1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" OutlineIndent SelectTaskField Row:=1, Column:="Nombre" SetTaskField Field:="Nombre", Value:="Devolucion Emision A" SelectTaskField Row:=1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=0, Column:="Duracin" SetTaskField Field:="Duracin", Value:="10" SelectTaskField Row:=1, Column:="Duracin" SelectTaskField Row:=-1, Column:="Duracin" SelectTaskField Row:=0, Column:="Nombre" SelectTaskField Row:=1, Column:="Nombre" SetTaskField Field:="Nombre", Value:="Emision B" SelectTaskField Row:=1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=0, Column:="Duracin" SetTaskField Field:="Duracin", Value:="2" SelectTaskField Row:=1, Column:="Duracin" SelectTaskField Row:=-1, Column:="Duracin" SelectTaskField Row:=0, Column:="Nombre" SelectTaskField Row:=1, Column:="Nombre" SetTaskField Field:="Nombre", Value:="Devolucion Emision B" SelectTaskField Row:=1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre"

SelectTaskField Row:=0, Column:="Duracin" SetTaskField Field:="Duracin", Value:="5" SelectTaskField Row:=1, Column:="Duracin" SelectTaskField Row:=-1, Column:="Duracin" SelectTaskField Row:=0, Column:="Nombre" SelectTaskField Row:=1, Column:="Nombre" SetTaskField Field:="Nombre", Value:="Emision 0" SelectTaskField Row:=1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=0, Column:="Duracin" SetTaskField Field:="Duracin", Value:="1" SelectTaskField Row:=1, Column:="Duracin" SelectTaskField Row:=-1, Column:="Duracin" SelectTaskField Row:=0, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=-1, Column:="Nombre" SelectTaskField Row:=0, Column:="Nombre", Height:=1, SelectTaskField Row:=0, Column:="Nombre", Height:=2, SelectTaskField Row:=0, Column:="Nombre", Height:=3, SelectTaskField Row:=0, Column:="Nombre", Height:=4, LinkTasks SelectTaskField Row:=0, Column:="Nombre" End Sub Sub Ingeniero() Dim ts As Tasks Dim tskTask As Task Dim rsResource As Resource Dim asAssignment As Assignment Dim colAssn As Collection Dim iIdx As Integer Dim Hh As Single Set ts = ActiveSelection.Tasks

Extend:=True Extend:=True Extend:=True Extend:=True

For Each tskTask In ts Set rsResource = ActiveProject.Resources("Ingeniero") Set colAssn = New Collection For Each asAssignment In tskTask.Assignments colAssn.Add asAssignment.Work Next asAssignment Set asAssignment = tskTask.Assignments.Add(tskTask.ID, rsResource.ID) Hh = InputBox("HorasHombre?", "Ingeniero") Hh = Hh * 60 colAssn.Add Hh ' work is stored as minutes For iIdx = 1 To colAssn.Count tskTask.Assignments(iIdx).Work = colAssn(iIdx) Next iIdx Next tskTask End Sub Sub Tecnico() Dim ts As Tasks Dim tskTask As Task Dim rsResource As Resource Dim asAssignment As Assignment Dim colAssn As Collection Dim iIdx As Integer

Dim Hh As Single Set ts = ActiveSelection.Tasks For Each tskTask In ts Set rsResource = ActiveProject.Resources("Tecnico") Set colAssn = New Collection For Each asAssignment In tskTask.Assignments colAssn.Add asAssignment.Work Next asAssignment Set asAssignment = tskTask.Assignments.Add(tskTask.ID, rsResource.ID) Hh = InputBox("HorasHombre?", "Tecnico") Hh = Hh * 60 colAssn.Add Hh ' work is stored as minutes For iIdx = 1 To colAssn.Count tskTask.Assignments(iIdx).Work = colAssn(iIdx) Next iIdx Next tskTask End Sub Sub IngTec() Call Ingeniero Call Tecnico End Sub Sub FiltroDescripcion() FilterApply Name:="Descripcion", Highlight:=True End Sub Sub FormatoActividad() ' Macro Macro1 ' Macro grabada el dom 10/02 por egonzalez. Dim t As Task Dim ts As Tasks Set ts = ActiveSelection.Tasks For Each t In ts OutlineOutdent SetRowHeight Unit:=2, Rows:=t.ID Next t SelectTaskField Row:=1, Column:="Nombre" End Sub

Sub AddAssignment() Dim tskTask As Task Dim rsResource As Resource Dim asAssignment As Assignment Dim colAssn As Collection Dim iIdx As Integer Set Set Set For tskTask = ActiveProject.Tasks(7) rsResource = ActiveProject.Resources("Ingeniero") colAssn = New Collection Each asAssignment In tskTask.Assignments colAssn.Add asAssignment.Work Next asAssignment Set asAssignment = tskTask.Assignments.Add(tskTask.ID, rsResource.ID) colAssn.Add 10 * 8 * 60 ' work is stored as minutes For iIdx = 1 To colAssn.Count

tskTask.Assignments(iIdx).Work = colAssn(iIdx) Next iIdx End Sub Sub DuracionTipo() Dim t As Task Dim ts As Tasks Set ts = ActiveProject.Tasks For Each t In ts If Not t.Summary Then ' t.Type = pjFixedWork If t.Name <> "Emision A" And t.Name <> "Emision B" And t.Name <> "Em ision 0" Then t.Text5 = "gn" End If End If Next t End Sub Sub Valor() Dim t As Task Dim ts As Tasks Dim Nombre As String Set ts = ActiveProject.Tasks For Each t In ts If Not t.Summary Then If t.Text1 = "1" Then t.Text1 = "Actividades sin problemas" End If End If Next t End Sub 'This module contains macros which will export 'tasks to excel and keep the task hierarchy. 'modify as necessary to include other task information 'Copyright Jack Dahlgren, Feb 2002 Option Explicit Dim xlRow As Excel.Range Dim xlCol As Excel.Range Sub TaskHierarchy() Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim Proj As Project Dim t As Task Dim Asgn As Assignment Dim ColumnCount As Integer Dim Columns As Integer Dim Tcount As Integer Set xlApp = New Excel.Application xlApp.Visible = True

AppActivate "Microsoft Excel" Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlBook.Worksheets.Add xlSheet.Name = ActiveProject.Name 'count columns needed ColumnCount = 0 For Each t In ActiveProject.Tasks If Not t Is Nothing Then If t.OutlineLevel > ColumnCount Then ColumnCount = t.OutlineLevel End If End If Next t 'Set Range to write to first cell Set xlRow = xlApp.ActiveCell xlRow = "Filename: " & ActiveProject.Name dwn 1 xlRow = "OutlineLevel" dwn 1 'label Columns For Columns = 1 To (ColumnCount + 1) Set xlCol = xlRow.Offset(0, Columns - 1) xlCol = Columns - 1 Next Columns rgt 2 xlCol = "Resource Name" rgt 1 xlCol = "work" rgt 1 xlCol = "actual work" Tcount = 0 For Each t In ActiveProject.Tasks If Not t Is Nothing Then dwn 1 Set xlCol = xlRow.Offset(0, t.OutlineLevel) xlCol = t.Name If t.Summary Then xlCol.Font.Bold = True End If For Each Asgn In t.Assignments dwn 1 Set xlCol = xlRow.Offset(0, Columns) xlCol = Asgn.ResourceName rgt 1 xlCol = (Asgn.Work / 480) & " Days" rgt 1 xlCol = (Asgn.ActualWork / 480) & " Days" Next Asgn Tcount = Tcount + 1 End If Next t AppActivate "Microsoft Project" MsgBox ("Macro Complete with " & Tcount & " Tasks Written") End Sub Sub dwn(i As Integer)

Set xlRow = xlRow.Offset(i, 0) End Sub Sub rgt(i As Integer) Set xlCol = xlCol.Offset(0, i) End Sub Option Explicit Sub writemyproperties() 'This macro exports all the built-in and custom project properties 'to a text file. It lists the index of the property, the name and the value. 'It demonstrates the use of a simple error handler to skip the errors that 'occur when a property is not defined or used. 'Copyright Jack Dahlgren, Feb 2002 Dim Dim Dim Dim mystring, MyFile As String fnum, myIndex As Integer myProj As Project skipme As Boolean

'set location and name of file to be written MyFile = "c:\" & ActiveProject.Name & "_properties.txt" skipme = False 'set and open file for output fnum = FreeFile() Open MyFile For Output As fnum 'write project info and then a blank line Write #fnum, "Built In Properties" Write #fnum, myIndex = 1 Set myProj = ActiveProject While myIndex <= myProj.BuiltinDocumentProperties.Count On Error GoTo ErrorHandler mystring = (myIndex & ") " & myProj.BuiltinDocumentProperties(myIndex).Name & ": " & myProj.BuiltinDocumentProperties(myIndex).Value) If Not skipme Then Write #fnum, mystring End If myIndex = myIndex + 1 skipme = False Wend Write #fnum, "-----------------------------------------------" Write #fnum, Write #fnum, "Custom Properties" Write #fnum, myIndex = 1 While myIndex <= myProj.CustomDocumentProperties.Count On Error GoTo ErrorHandler If Not skipme Then mystring = (myIndex & ") " & myProj.CustomDocumentProperties(myIndex).Na me & ": " & myProj.CustomDocumentProperties(myIndex).Value) Write #fnum, mystring End If myIndex = myIndex + 1 skipme = False Wend Close #fnum

ErrorHandler: skipme = True Resume Next End Sub Sub Filter_Select() 'This Macro filters your gantt view to show only the 'tasks that you have selected. It is helpful when you want 'to present a certain groups of tasks or 'you want to show a set of tasks that would 'be difficult to filter for. 'This macro overwrites data in the flag5 field 'Thanks to Michael Edwards for catching the bug in this one. 'version history: 'v1.00 Feb, 2002 'v1.01 Mar 14, 2002 (corrected field used for filter) 'Copyright Jack Dahlgren Feb. 2002 Dim jTasks As Tasks Dim jTask As Task 'clear the flag field For Each jTask In ActiveProject.Tasks If Not jTask Is Nothing Then jTask.Flag5 = "No" End If Next jTask 'set the flag field for the selected tasks Set jTasks = ActiveSelection.Tasks For Each jTask In jTasks If Not jTask Is Nothing Then jTask.Flag5 = "Yes" End If Next jTask 'filter to show just the selected tasks FilterEdit Name:="select", TaskFilter:=True, Create:=True, OverwriteExisting :=True, FieldName:="Flag5", test:="equals", Value:="Yes", ShowInMenu:=False, Sho wSummaryTasks:=False FilterApply Name:="select" End Sub Option Explicit 'Macros to Remove contraints from tasks that are kept in place by logic 'This sets the tasks to have a constraint type of 0 which is "As Soon As Possibl e" 'You can reverse it by running Restore_NonLogic_Contraints 'Copyright Jack Dahlgren 4/17/00 Sub Remove_NonLogic_Constraints() Dim ProjTasks As Tasks Dim ProjTask As Task

Dim TaskDeps As TaskDependencies If MsgBox("This Macro will remove All Constraints from tasks that have predecess ors. Do you want to continue?", vbYesNo) = vbNo Then End Set ProjTasks = ActiveProject.Tasks For Each ProjTask In ProjTasks 'these if statements step th rough all tasks in the project If Not (ProjTask Is Nothing) Then 'this handles blank line in the file If ProjTask.Summary = False Then 'this handles summary tasks which are only allowed to be fixed duration If ProjTask.ExternalTask = False Then 'this handles external tasks ProjTask.Date1 = "" 'Clears the field we use to restore original constraint date ProjTask.Number15 = 0 'Clear the field we use to restore const raint type If ProjTask.TaskDependencies.Count > 0 Then 'selects tasks with 1 or more dependencies ProjTask.Date1 = ProjTask.ConstraintDate 'Stores restore data into fields ProjTask.Number15 = ProjTask.ConstraintType 'Stores restore dat a into fields ProjTask.ConstraintType = 0 'Sets task to as soon as possibl e End If End If End If End If Next ProjTask End Sub 'Macro to Restore contraints that were erased by the Remove_NonLogic_Contraints( ) macro 'This sets resets the tasks to have their original constraint types and dates 'Copyright Jack Dahlgren 4/17/00 Sub Dim Dim Dim Restore_NonLogic_Contraints() ProjTasks As Tasks ProjTask As Task TaskDeps As TaskDependencies

If MsgBox("This Macro will restore All Constraints for tasks that have predecess ors. Do you want to continue?", vbYesNo) = vbNo Then End Set ProjTasks = ActiveProject.Tasks For Each ProjTask In ProjTasks rough all tasks in the project If Not (ProjTask Is Nothing) Then the file If ProjTask.Summary = False Then which are only allowed to be fixed duration If ProjTask.ExternalTask = False Then If ProjTask.TaskDependencies.Count > 0 with dependencies 'these if statements step th 'this handles blank line in 'this handles summary tasks 'this handles external tasks Then 'Selects only tasks

ProjTask.ConstraintType = ProjTask.Number15 rom storage fields ProjTask.ConstraintDate = ProjTask.Date1 rom storage fields End If End If End If End If Next ProjTask End Sub

'restores data f 'restores data f

Sub allgreen() 'This macro shows how to set a barstyle depending on a certain 'value in the text5 field. Right now the case statement is 'commented out, so it will make all of your tasks green 'If you comment out the green line, this macro is useful 'to clear any custom formatting that you may have applied to 'specific tasks. 'Copyright Jack Dahlgren, Feb. 2002 Dim t As Task For Each t In ActiveProject.Tasks Select Case LCase(t.Text5) Case "gn" GanttBarFormat TaskID:=t.ID, Reset:=True 'comment out this line if you don't want all the tasks green GanttBarFormat TaskID:=t.ID, MiddleColor:=pjGreen, StartColor:=p jGreen, EndColor:=pjGreen Case Else End Select Next t End Sub Sub PrintResourceCharts() 'This macro will pring a gantt chart for every resource in the project 'It will automatically adjust the timescale to show all of the resource's ac tivities 'Copyright Jack Dahlgren, Feb. 2002 Dim r As Resource Dim mystring As String ViewApply Name:="&Gantt Chart" For Each r In ActiveProject.Resources If r.Assignments.Count > 0 Then mystring = r.Name FilterEdit Name:="Filter 1", TaskFilter:=True, Create:=True, _ OverwriteExisting:=True, FieldName:="Resource Names", test:="Contains ex actly", _ Value:=mystring, ShowInMenu:=False, ShowSummaryTasks:=False FilterApply "Filter 1" SelectAll ZoomTimescale Selection:=True SendKeys "{ENTER}" FilePrint MsgBox (r.Name) End If

Next r End Sub

'This is the master macro Sub Trace() Dim Forward As Boolean Dim SelectedID As Integer Dim jString As String Dim IsSum As Boolean Dim IsCrit As Boolean Dim IsDrive As Boolean Dim jTask As Task Dim t As Task Dim ts As Tasks Dim Nu Set ts = ActiveSelection.Tasks For Each t In ts Nu = t.ID Next t If ActiveSelection = 0 Then MsgBox "You must have just one task selected for this macro to work" Exit Sub End If If ActiveSelection.Tasks.Count <> 1 Then MsgBox "You must have just one task selected for this macro to work" Exit Sub End If 'This sets flag used later for tracing paths. jString = InputBox(("Please Enter Fan Type" & Chr(13) & Chr(13) & "P (Pred ecessors)" & Chr(13) & "S (Successors)" & Chr(13) & "A (All)"), "Fan-out Dep endencies") jString = UCase(Left(jString, 1)) If jString = "" Then Exit Sub End If ClearFlags IsCrit = False For Each jTask In ActiveSelection.Tasks If jTask.Summary = True Then MsgBox "You have selected a summary task. Select a taks or milestone and try again" Exit Sub End If If jTask.Critical = True Then If MsgBox("Do you want to display only Critical Tasks?", 260, "Display C ritical Tasks Only?") = vbYes Then IsCrit = True End If End If

Next jTask 'This sets the flag for 0 free float (driving) tasks IsDrive = False For Each jTask In ActiveSelection.Tasks If IsCrit = False Then If MsgBox("Do you want to display only Driving Tasks?", 260, "Display Dr iving Tasks Only?") = vbYes Then IsDrive = True End If End If Next jTask Select Case jString Case "P" TracePredecessors Case "S" TraceSuccessors Case Else TraceAll End Select FilterMe If SelectedID > 0 Then Find Field:="ID", test:="Igual a", Value:=SelectedID, Next:=True EditGoTo ID:=Nu End Sub ' Set all tasks Flag5 to false Private Sub ClearFlags() Dim jTask As Task For Each jTask In ActiveProject.Tasks If Not (jTask Is Nothing) Then If jTask.Flag5 = True Then jTask.Flag5 = False End If Next jTask End Sub ' Traces Only Successor Tasks - forward equal to true Private Sub TraceSuccessors() SelectedID = 0 Forward = True MarkItem End Sub ' Traces Only Predecessor Tasks - forward equal to false Private Sub TracePredecessors() SelectedID = 0 Forward = False MarkItem End Sub ' Traces All Tasks - one pass for successors, then one for predecessors Private Sub TraceAll() SelectedID = 0 Forward = True ' mark successors MarkItem Forward = False ' mark predecessors MarkItem End Sub ' Marks all tasks feeding by selected task(s) Private Sub MarkItem() Dim jTask As Task, jjTask As Task For Each jTask In ActiveSelection.Tasks If Not (jTask Is Nothing) Then SelectedID = jTask.ID

If Not (jjTask Is Nothing) Then If Not Forward Then Fan jjTask Else jjTask.Flag5 = True End If If Not (jjTask Is Nothing) Then If Forward Then Fan jjTask Else jjTask.Flag5 = True End If End If Else Fan jTask End If End If Next jTask End Sub ' Walks through all predecessors or successors to a task and marks their flag5 a s true Private Sub Fan(jTask As Task) Dim jjTask As Task jTask.Flag5 = True If Forward Then For Each jjTask In jTask.SuccessorTasks If jjTask.Flag5 <> True Then If IsCrit And Not IsDrive Then If jjTask.Critical = True Then Fan jjTask End If ElseIf IsDrive = True Then If jjTask.FreeSlack < 100 Then Fan jjTask End If Else Fan jjTask End If End If Next jjTask Else For Each jjTask In jTask.PredecessorTasks If jjTask.Flag5 <> True Then If IsCrit And Not IsDrive Then If jjTask.Critical = True Then Fan jjTask End If ElseIf IsDrive = True Then If jjTask.FreeSlack < 100 Then Fan jjTask End If Else Fan jjTask End If End If Next jjTask End If End Sub

' Filter with or without summary tasks Private Sub FilterMe() If MsgBox("Do you want to display Summary Tasks?", vbYesNo, "Display Summary Tasks?") = vbYes Then IsSum = True Else: IsSum = False End If OutlineShowAllTasks FilterEdit Name:="_Trace", TaskFilter:=True, Create:=True, OverwriteExisting :=True, FieldName:="Indicador5", test:="Igual a", Value:="S", ShowInMenu:=True, S howSummaryTasks:=True FilterApply Name:="_Trace" End Sub Sub SinFiltro() Dim t As Task Dim ts As Tasks Dim te For Each t In ActiveSelection.Tasks te = t.ID FilterApply Name:="&Todas las tareas" Next t EditGoTo ID:=te End Sub Sub AltoResumen() Dim t As Task Dim ts As Tasks Set ts = ActiveProject.Tasks For Each t In ts If t.Summary Then SetRowHeight Unit:=2, Rows:=t.ID End If Next t End Sub

You might also like