This example, which runs with Microsoft Project as a VBA macro will:
1
Use the active Microsoft Project schedule.
2
Generate a Milestones Professional schedule with DataGraph, like
the one shown below.
TRY THIS EXAMPLE
VISUAL BASIC CODE (Milestones
interface calls shown in Blue)
Public Sub ProjectExample2()
Dim objMilestones As Object
Dim currentrow As Integer
Dim Tsk As Task
Dim currentpage As Integer
Dim LinesPerPage As Integer
Dim NewPage As Integer
Dim symbolcount As Integer
'First, check to see if there are any
tasks in the current MS Project file
'If not, put up a message box and quit
numberofprojecttasks = MSProject.ActiveProject.Tasks.Count
If numberofprojecttasks < 1 Then
MsgBox ("No Tasks in the MS Project Schedule")
GoTo ExitLabel
End If
' Create Milestones Professional Object
Set objMilestones = CreateObject("Milestones")
NewPage = 1
currentpage = 1
With objMilestones
.Activate
.KeepScheduleOpen
.Template "ProjectTemplate2.mtp"
label1:
'Set all symbols on the Milestones
Professional schedule to a size of 0.5
.SetGlobalSymbolSize 0.5
label2:
'Find out (from Project), how many tasks are in the active project
numberofrows = MSProject.ActiveProject.Tasks.Count
'Set the # of lines per page on
the Milestones Professional schedule to 40
.SetLinesPerPage 40
LinesPerPage = 40
'Set the default column text
font size to 9 point
.SetFontSize 1, 9
'Set the default symbol text
font size to 9 point
.SetFontSize 2, 9
'Set the schedule's Title
.SetTitle1 ActiveProject.Title
.SetTitle2 "Author: " &
ActiveProject.Author
.SetTitle3 "Start Date: " &
ActiveProject.ProjectStart
'Refresh the screen
.refresh
putouttasks:
currentrow = 0
For Each Tsk In
MSProject.ActiveProject.Tasks
'currentrow keeps
track of the row # on the Milestones Professional schedule
currentrow = currentrow + 1
On Error GoTo
addblankrow
'Add the task name
to column 1 of the current row
.PutCell currentrow, 1,
Tsk.Name
'Add the Cost value
to to column 6. This column is used for the ValueSet/DataGraph
.PutCell currentrow, 6,
Tsk.Cost
'Set the outline
level for the current task
.SetOutlineLevel currentrow,
Tsk.OutlineLevel
'Set the %complete for the task
If Tsk.PercentComplete >= 0 And Tsk.PercentComplete <= 100 Then
.SetPercentComplete currentrow,
Tsk.PercentComplete
End If
'Display progress in the status
bar
.SetStatusMessage "task: " +
Str(currentrow)
'Figure out which page the
current task is on
NewPage = Fix((currentrow - 1) / LinesPerPage) + 1
'If necessary, switch to a new
page
If NewPage > currentpage Then
.SetCurrentPage NewPage
currentpage = NewPage
End If
addblankrow:
Next Tsk
'Set the Milestones Professional
schedule's start and end dates, based on the dates in MS Project
.SetEndDate Format(ActiveProject.ProjectFinish,
"mm/dd/yy")
.SetStartDate
Format(ActiveProject.ProjectStart, "mm/dd/yy")
.SetCurrentPage 1