1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| Sub CreateProjectRotationCalendar()
Dim Answer, FirstDayIn, iRotations, NbRot, WeeksOn, WeeksOff As Integer
Dim DateIn As Date
Dim oCal As Calendar
Const BaseCalName = "Standard"
Collect:
WeeksOn = InputBox("Please input number of worked weeks", "Definition of rotations")
WeeksOff = InputBox("Please input number of weeks off", "Definition of rotations")
CalName = "Rotations " & WeeksOn & "/" & WeeksOff
Answer = MsgBox("Rotations will be " & WeeksOn & " weeks on / " & WeeksOff & " weeks off." & Chr(10) & "Please confirm.", vbYesNo)
If Answer = 7 Then
GoTo Collect
End If
On Error Resume Next
Set oCal = ActiveProject.BaseCalendars(CalName)
If Not oCal Is Nothing Then
oCal.Delete
End If
Application.BaseCalendarCreate CalName, BaseCalName
'Get information
FirstDayIn = InputBox("Please input number of days before Resource to be on site and start rotation cycles", "Start date of rotations 8/2")
NbRot = InputBox("Please input number of rotation cycles", "Number of rotations required")
DateIn = Now + FirstDayIn
For iRotations = 1 To NbRot
' SSet days weeks off to non-working, other days based on standard calendar
ActiveProject.BaseCalendars(CalName).Exceptions.Add Type:=pjDaily, Start:=DateIn + (7 * WeeksOn), Finish:=DateIn + (7 * (WeeksOn + WeeksOff)) - 1, Name:="Left for rotation"
'Prepare for next loop
DateIn = DateIn + (WeeksOn + WeeksOff) * 7
Next
MsgBox "Done", vbOKOnly + vbExclamation
End Sub |
Partager