Milestones Professional Automation: Visual Basic Automation Examples

Warning: The information on these pages should only be used by software developers who are familiar with a Windows programming environment. KIDASA does not take responsibility for any damage caused to your information or computer due to programming errors.

Visual Basic Automation Example #1

Here’s an example which illustrates many of Milestones Professional’s OLE Automation methods. It builds a simple schedule, adds curtains, shades a task line and adds a duration SmartColumn.

The Code:

Sub Main()
Dim objproject, objmilestones, tasks, T As Object

'Create the Milestones object
Set objmilestones = CreateObject("Milestones")

'Start Milestones
objmilestones.Activate

'set up a column, 2 inches wide
objmilestones.SetColumnWidth 1, 2

'Set up the toolbox to have a variety of symbols and colors
For ncounter = 0 To 11
objmilestones.settoolboxsymbolproperty ncounter + 1, "Type", ncounter + 1
objmilestones.settoolboxsymbolproperty ncounter + 1, "FillColor", ncounter + 1
objmilestones.settoolboxsymbolproperty ncounter + 1, "DatePosition", ncounter + 2
objmilestones.settoolboxsymbolproperty ncounter + 1, "ShowShadow", "on"
objmilestones.settoolboxsymbolproperty ncounter + 1, "ShadowColor", 8
objmilestones.settoolboxsymbolproperty ncounter + 1, "ShadowSize", 2
objmilestones.settoolboxsymbolproperty ncounter + 1, "DateBack", "Transparent"
Next ncounter

'Add tasks and symbols to the schedule
For ncounter = 0 To 11
Dim startsymboltype As Integer
startsymboltype = ncounter * 2 + 1
strTemp = "This is Task Row " + CStr(ncounter)

objmilestones.PutCell ncounter + 1, 1, strTemp

strTemp = CStr(ncounter + 1) + "/12/2000"

objmilestones.AddTaskUsingDuration ncounter + 1, strTemp, startsymboltype, ncounter + 1, 0, startsymboltype + 1, 55, "day"

objmilestones.settasklinegrid ncounter + 1, 0, ncounter + 1, 0
objmilestones.settasklinegrid ncounter + 1, 1, ncounter + 1, 0
objmilestones.settasklinegrid ncounter + 1, 2, ncounter + 1, 0

Next ncounter

'shade the 5th task line
objmilestones.SetTaskLineShade 5, 0, 2
objmilestones.SetTaskLineShade 5, 1, 15
objmilestones.SetTaskLineShade 5, 2, 18

'Add a %duration column
objmilestones.SetColumnWidth 6, 1#
objmilestones.SetColumnProperty 6, "SmartColumn", "duration"
objmilestones.SetColumnProperty 6, "TextAlign", 2
objmilestones.SetColumnProperty 6, "ColumnHeadingLine1", "Days"

'set the start and end dates
objmilestones.SetStartDate "01/01/2000"
objmilestones.SetEndDate "06/30/2001"

'set up curtains
objmilestones.AddCurtain "1/1/2000", "1/15/2000"
objmilestones.AddCurtain "4/1/2000", "4/15/2000"
objmilestones.AddCurtain "7/1/2000", "7/15/2000"
objmilestones.AddCurtain "10/1/2000", "10/15/2000"
objmilestones.AddCurtain "1/1/2001", "1/15/2001"
objmilestones.AddCurtain "4/1/2001", "4/15/2001"
objmilestones.SetCurtainProperties 1, "1/1/2000", "1/31/2000", 1, 18, 1, 0
objmilestones.SetCurtainProperties 2, "4/1/2000", "4/30/2000", 4, 15, 1, 0
objmilestones.SetCurtainProperties 3, "7/1/2000", "7/31/2000", 7, 12, 1, 0
objmilestones.SetCurtainProperties 4, "10/1/2000", "10/15/2000", 10, 9, 1, 0
objmilestones.SetCurtainProperties 5, "1/1/2001", "2/15/2001", 13, 6, 1, 0
objmilestones.SetCurtainProperties 6, "4/1/2001", "4/30/2001", 16, 3, 1, 0

objmilestones.Refresh

'keep the schedule open
objmilestones.keepscheduleopen

'Maximize the Milestones window
objmilestones.MaximizeWindow

Exit Sub

End Sub

To try this example:
Click here to download a Zip file (MilestonesVBExample1.Zip) containing the above VB code.

Visual Basic Automation Example #2

Here’s an example which illustrates many of Milestones Professional’s OLE Automation methods. It builds a simple schedule, adds curtains, shades a task line and adds a duration SmartColumn.

The Code:

Dim objproject, objmilestones, tasks, T As Object
'Create the Milestones object
Set objmilestones = CreateObject("Milestones")

SUBSTITUTE YOUR OWN FILE HERE

'Create the MS Project object
Set objproject = GetObject("c:testprojectexample.mpp")

'Create the tasks object
Set tasks = objproject.tasks
If tasks.Count < 1 Then
    MsgBox "No tasks in project file"
    End
End If

'Start Milestones
objmilestones.Activate

'Set Schedule start and end dates
objmilestones.SetStartDate objproject.start
objmilestones.SetEndDate objproject.Finish

'Format the schedule

'first, make sure there are no columns
For x = 1 To 10
    objmilestones.SetColumnWidth x, 0#
Next x

'set up one column on the left side of the schedule
objmilestones.SetColumnWidth 1, 2.5

objmilestones.SetSummaryBarDisplay 0

objmilestones.setcolumnproperty 1, "SmartColumn", "none"

'it will be outlined, so set the amount to indent for each outline level
objmilestones.setcolumnproperty 1, "Indent", 0.2

'make it left-justified
objmilestones.setcolumnproperty 1, "TextAlign", 0

'add a column heading
objmilestones.setcolumnproperty 1, "ColumnHeadingLine1", "Task"
objmilestones.setcolumnproperty 1, "ColumnHeadingLine2", "Name"

'set up date headings
objmilestones.SetDateHeading 1, "Yearly", 1
objmilestones.SetDateHeading 2, "Monthly", 4
objmilestones.SetDateHeading 3, "None", 0
objmilestones.SetDateHeading 4, "None", 0

'we will have 22 tasks on each page
objmilestones.SetLinesPerPage 22

'add a curtain to shade the first 15 days of January
objmilestones.AddCurtain "01/01/1999", "01/15/1999"
objmilestones.SetCurtainProperties 1, "01/01/1999", "01/15/1999", 2, 4, 8, 0

'Add titles using information in MS Project file
objmilestones.SetTitle1 "Title: " + objproject.Title
objmilestones.SetTitle2 "Subject: " + objproject.Subject
objmilestones.SetTitle3 "Author: " + objproject.Author

'set up the symbology for summary tasks
objmilestones.settoolboxsymbolproperty 1, "Type", 40 'triangle
objmilestones.settoolboxsymbolproperty 1, "DatePosition", 13 'hide
objmilestones.settoolboxsymbolproperty 1, "FillColor", 18 'black
objmilestones.SetToolboxHorizontalConnectorProperty 1, "Type", 20 'Upper bar
objmilestones.SetToolboxHorizontalConnectorProperty 1, "FillColor", 18 'Black

'set up the symbology for non-summary tasks
objmilestones.settoolboxsymbolproperty 3, "Type", 45 'circled triangle-small
objmilestones.settoolboxsymbolproperty 3, "DatePosition", 13 'hide
objmilestones.SetToolboxHorizontalConnectorProperty 2, "Type", 20 'Upper bar
objmilestones.SetToolboxHorizontalConnectorProperty 2, "FillColor", 4 'Blue
objmilestones.SetToolboxHorizontalConnectorProperty 2, "ShadowColor", 7 'Gray

'set up symbology for critical tasks
objmilestones.SetToolboxHorizontalConnectorProperty 3, "Type", 20 'Upper bar
objmilestones.SetToolboxHorizontalConnectorProperty 3, "FillColor", 6 'Red
objmilestones.settoolboxsymbolproperty 5, "Type", 40 'triangle
objmilestones.settoolboxsymbolproperty 5, "DatePosition", 13 'hide
objmilestones.settoolboxsymbolproperty 5, "FillColor", 6 'Red

'set up symbology for one-day events (milestones)
objmilestones.settoolboxsymbolproperty 7, "Type", 3
objmilestones.settoolboxsymbolproperty 7, "FillColor", 1 'Aqua

'set up the legend
objmilestones.SetLegendHeight 1#
objmilestones.SetLegendProperty "entriesperrow", 3
objmilestones.SetLegendSymbology 1, 1, 1, 1 ' summary
objmilestones.SetLegendText 1, "Summary", ""
objmilestones.SetLegendText 2, "Planned", ""
objmilestones.SetLegendText 3, "Critical", ""
objmilestones.SetLegendSymbology 2, 3, 2, 3 'planned
objmilestones.SetLegendSymbology 3, 5, 3, 5 'critical

'loop through the list of MS Project tasks and build
'Milestones schedule
currentrow = 0

For Each T In tasks
    currentrow = currentrow + 1

    objmilestones.settasklinegrid currentrow, 1, 7, 17

    If T.Summary = True Then
      symboltype = 1
      connectortype = 1
    Else
      symboltype = 3
      connectortype = 2
    End If

    If T.Critical = True Then
      symboltype = 5
      connectortype = 3
    End If

'add text to the task name column
    objmilestones.PutCell currentrow, 1, T.Name

    If Format(T.start, "MM/DD/YY") = Format(T.Finish, "MM/DD/YY") Then

'single day milestones
    objmilestones.AddSymbol currentrow, Format(T.Finish, "MM/DD/YY"), 7

    If T.Critical Then

      objmilestones.setsymbolproperty currentrow, 1, "FillColor", 6

    Else

'add start+finish dates
       objmilestones.AddSymbol currentrow, Format(T.start, "MM/DD/YY"), symboltype, connectortype, 2
       objmilestones.AddSymbol currentrow, Format(T.Finish, "MM/DD/YY"), symboltype

        If T.Critical = True Then

'color critical symbols red
        objmilestones.setsymbolproperty currentrow, 1, "FillColor", 6
        objmilestones.setsymbolproperty currentrow, 2, "FillColor", 6
        'shade the critical tasks
        objmilestones.settasklineshade currentrow, 0, 6
        objmilestones.settasklineshade currentrow, 1, 6
       End If
    End If

'set the outline level
    objmilestones.setoutlinelevel currentrow, T.Outlinelevel

'set the font size
    objmilestones.settasklinefontheight currentrow, 10

'display a message in the status bar
    objmilestones.setstatusmessage "Task: " + Str(currentrow)
Next T

'keep the schedule open
objmilestones.keepscheduleopen

'Maximize the Milestones window
objmilestones.MaximizeWindow

Exit Sub

End Sub

To try this example:
Click here to download a Zip file (MilestonesVBExample2.Zip) containing the above VB code. Note that you will need Microsoft Project and a Microsoft Project MPP file (any MPP file with tasks will work) to run this example. In the program, change the referenced MPP file name to a file name of one of the MPP files on your computer.

Visual Basic Automation Example #3

Here's an example which builds a set of schedules and then publishes them for the Internet (complete with HyperLinks) with the SaveHTMLDrillDown method.

The Code:

Sub Main()

Dim objproject, tasks, T As Object

Dim objmilestonesmain As Variant

Dim objmilestonessub(7) As Variant

'Start up Milestones

Set objmilestonesmain = CreateObject("Milestones")
objmilestonesmain.Activate

'create a folder for the schedules

On Error GoTo folderexists

Set fs = CreateObject("Scripting.FileSystemObject")

fs.createfolder "c:tempmilesx"

folderexists:

'create 5 separate project schedules

For x = 1 To 5

Set objmilestonessub(x) = CreateObject("Milestones")

With objmilestonessub(x)

.Activate

'symbol 1 will be a lime inverted triangle

.settoolboxsymbolproperty 1, "Type", 1

.settoolboxsymbolproperty 1, "FillColor", 5

'symbol 2 will be a red triangle

.settoolboxsymbolproperty 2, "Type", 2

.settoolboxsymbolproperty 2, "FillColor", 6

'symbols 3 and 4 will be black stars

.settoolboxsymbolproperty 3, "Type", 5

.settoolboxsymbolproperty 3, "FillColor", 18

.settoolboxsymbolproperty 4, "Type", 5

.settoolboxsymbolproperty 4, "FillColor", 18

'symbols 5 and 6 will be blue squares

.settoolboxsymbolproperty 5, "Type", 6

.settoolboxsymbolproperty 5, "FillColor", 3

.settoolboxsymbolproperty 6, "Type", 6

.settoolboxsymbolproperty 4, "FillColor", 3

'symbol 7 will be a yellow 5-sided triangle

.settoolboxsymbolproperty 7, "Type", 40

.settoolboxsymbolproperty 7, "FillColor", 4

'symbol 8 will be a down pointing 5-sided triangle

.settoolboxsymbolproperty 8, "Type", 41

.settoolboxsymbolproperty 8, "FillColor", 4

'symbols 9 and 10 will be green octagons

.settoolboxsymbolproperty 9, "Type", 56

.settoolboxsymbolproperty 9, "FillColor", 13

.settoolboxsymbolproperty 10, "Type", 56

.settoolboxsymbolproperty 10, "FillColor", 13

'set up one connector in the toolbox

.settoolboxhorizontalconnectorproperty 1, "Type", 7

'set up a couple of columns

.setcolumnproperty 1, "TextAlign", 1

.setcolumnproperty 2, "TextAlign", 1

.setcolumnwidth 1, 2.4

.setcolumnwidth 2, 1.5

.setcolumnproperty 2, "SmartColumn", "duration"

.setcolumnproperty 1, "ColumnHeadingLine1", "Project " + Str(x)

.setcolumnproperty 1, "ColumnHeadingLine2", "Tasks"

.setcolumnproperty 2, "ColumnHeadingLine1", "Duration"

.setfontstyle 12, 1, 18

.setfontstyle 6, 1, 18

.setfontstyle 13, 1, 18

.setfontstyle 3, 1, 24

.setfontstyle 4, 1, 24

'hide the date for all symbols

For X2 = 1 To 10

.settoolboxsymbolproperty X2, "DatePosition", 13

Next X2

.SetStartAndEndDates "06/01/2001", "11/15/2001"

For tasks = 1 To 5

taskname = "Project " + Str(x) + " Task: " + Str(tasks)

.putcell tasks, 3, taskname

symboltype1 = tasks * 2 - 1

symboltype2 = tasks * 2

connectortype = 1

thedate = Trim(Str(tasks + 5)) + "/15/2001"

.addtaskusingduration tasks, thedate, symboltype1, connectortype, 0, symboltype2, 12 + tasks, "Day"

.setsymbolproperty tasks, 1, "SymbolDatePosition", 2

.setsymbolproperty tasks, 2, "SymbolDatePosition", 3

.setsymbolproperty tasks, 1, "DateBack", "transparent"

.setsymbolproperty tasks, 2, "DateBack", "transparent"

.setsymbolproperty tasks, 1, "TextBack", "transparent"

.setsymbolproperty tasks, 2, "TextBack", "transparent"
.refreshtask tasks
Next tasks

.SetTitle1 "Project " + Str(x)

.SetTitle2 "DrillDown Example"

.SetTitle3 "Note: dummy dates used for this example!"

.setlinesperpage 5
FileNamezzz = "c:tempmilesxproject" + Trim(Str(x)) + ".mla"

.save FileNamezzz

.Close

End With

Next x 'next schedule

'make the top level schedule

Set objmilestonessub(6) = CreateObject("Milestones")

With objmilestonessub(6)

'Start Milestones

.Activate

.SetStartAndEndDates "06/01/2001", "11/15/2001"

.putcell 1, 3, "Project 1"

.putcell 2, 3, "Project 2"

.putcell 3, 3, "Project 3"

.putcell 4, 3, "Project 4"

.putcell 5, 3, "Project 5"

.setlinesperpage 5

.addtaskusingduration 1, "6/15/2001", 1, 1, 0, 2, 20, "Day"

.addtaskusingduration 2, "7/15/2001", 1, 1, 0, 2, 20, "Day"

.addtaskusingduration 3, "8/15/2001", 1, 1, 0, 2, 20, "Day"

.addtaskusingduration 4, "9/15/2001", 1, 1, 0, 2, 20, "Day"

.addtaskusingduration 5, "10/15/2001", 1, 1, 0, 2, 20, "Day"

For x = 1 To 5

.setsymbolproperty x, 1, "SymbolText", "Click", 1

.setsymbolproperty x, 1, "SymbolText", "Here", 2

.setsymbolproperty x, 1, "DateBack", "transparent"

.setsymbolproperty x, 2, "DateBack", "transparent"

.setsymbolproperty x, 1, "TextBack", "transparent"

.setsymbolproperty x, 2, "TextBack", "transparent"

Next x

.setcolumnproperty 1, "TextAlign", 1

.setcolumnwidth 1, 2.4

.SetTitle1 "Main Project Schedule"

.SetTitle2 "Click a start symbol to drill down"

.setfontstyle 3, 1, 24

.setfontstyle 4, 1, 24

.setsymbolproperty 1, 1, "Symbolhyperlink", "C:tempmilesxproject1.mla"

.setsymbolproperty 2, 1, "Symbolhyperlink", "C:tempmilesxproject2.mla"

.setsymbolproperty 3, 1, "Symbolhyperlink", "C:tempmilesxproject3.mla"

.setsymbolproperty 4, 1, "Symbolhyperlink", "C:tempmilesxproject4.mla"

.setsymbolproperty 5, 1, "Symbolhyperlink", "C:tempmilesxproject5.mla"

.save "c:tempmilesxtoplevel3.mla"

.keepscheduleopen

End With

'create the HTML files with hotspots (one step! check it out!)

With objmilestonessub(6)
.setinternetpublishingoptions 2, "Test", 1, 1, 1, 1, "", 99, 3, 1, 1, 1, 1, 1, 0, 1
.SaveHTMLHyperlinkDrillDown "c:tempmilesxtoplevel3.htm"

End With

Exit Sub

End Sub
To try this example:
Click here to download a Zip file (MilestonesVBExample3.Zip) containing the above VB code.
Click here for a VB.Net version

Visual Basic Automation Example #4

Here's an example which shows how you might have a user interactively "tag" symbols on a Milestones Professional schedule. This process might be useful when you need to later update a schedule with data from a database.

Public objproject, objmilestones, tasks, T As Object
Public stringtag As String

Sub main()
Dim filename As String

filename = InputBox("Enter a File Name", "Test VB Program", "c:filename.mla")

Set objmilestones = GetObject(filename)

objmilestones.KeepScheduleOpen

'Maximize the Milestones window
objmilestones.MaximizeWindow

Form1.Show

End Sub
  
FORM1 CODE
Private Sub Command1_Click()

stringtag = Text1.Text

taskindex = objmilestones.GetTaskLineOfSelectedSymbol

If taskindex < 1 Then
If taskindex = 0 Then MsgBox "no symbol is selected"
If taskindex < 0 Then MsgBox "more than one symbol is selected"
GoTo forgetit
End If

symbolindex = objmilestones.GetSelectedSymbolInLine(taskindex)

If symbolindex < 1 Then
If symbolindex = 0 Then MsgBox "no symbol is selected"
If symbolindex < 0 Then MsgBox "more than one symbol is selected"
GoTo forgetit
End If

objmilestones.setsymbolproperty taskindex, symbolindex, "SymbolNotes", stringtag
objmilestones.refreshtask taskindex
forgetit:
End Sub

Private Sub Command2_Click()
Form1.Hide
End
End Sub

Private Sub Command3_Click()

'Dim taskindex, symbolindex, numtsks, numsymbols As Integer
Dim symbolindex As Integer, symbolindex2 As Integer
Dim taskindex As Integer, taskindex2 As Integer
Dim numsymbols As Integer


taskindex = objmilestones.GetTaskLineOfSelectedSymbol

If taskindex < 1 Then
If taskindex = 0 Then MsgBox "no symbol is selected"
If taskindex < 0 Then MsgBox "more than one symbol is selected"
GoTo forgetit
End If

symbolindex = objmilestones.GetSelectedSymbolInLine(taskindex)

If symbolindex < 1 Then
If symbolindex = 0 Then MsgBox "no symbol is selected"
If symbolindex < 0 Then MsgBox "more than one symbol is selected" GoTo forgetit End If numtsks = objmilestones.getnumberoflines numsymbols = objmilestones.getnumberofsymbolsinline(taskindex) symbolindex2 = symbolindex + 1 If symbolindex2 > numsymbols Then 'move to the first symbol
  xxx: taskindex = taskindex + 1
    If taskindex > numtsks Then taskindex = 1
    symbolindex2 = 1
    numsymbols = objmilestones.getnumberofsymbolsinline(taskindex)
    If numsymbols > 0 Then GoTo allwell
    GoTo xxx
End If


allwell:
objmilestones.selectsymbolinline 0, 0
objmilestones.selectsymbolinline taskindex, symbolindex2
objmilestones.refreshtask taskindex

forgetit:
End Sub

To try this example:
Click here to download a Zip file (MilestonesVBExample4.Zip) containing VB Code to do this. Most of the code is in the supporting Form (Form1).

Visual Basic Automation Example #5

This is an example of using Visual Basic and Milestones to easily change the current date of all the ML7 files in a folder.

The Code:

'Public Sub Main()
'------------------------------------------------------------
' Sets the Data Date for all schedules in a folder
' By Ray Messinger : 20-Aug-02
'------------------------------------------------------------
Dim objmilestones(50)
today = Date
pYear = Year(today)
pMonth = Month(today) - 1

'--- Calc the Last Day of the provious month ---
LastEOM = DateSerial(pYear, pMonth + 1, 0)

'---- Get the Datadate -----
DataDate = InputBox("Enter the Data Date", "Data Date Set", LastEOM)
If DataDate = "" Then WScript.Quit
DataDate = Month(DataDate) & "/" & Day(DataDate) & "/" & Year(DataDate)

'---
Dim fso, folder, f1, fc
Set fso = CreateObject("Scripting.FileSystemObject")

'--- Change this to the folder name you would like to use:
folderspec = "C:test"
Set folder = fso.GetFolder(folderspec)
Set fc = folder.Files
fcnt = 0
For Each f1 In fc
FName = f1.Name
MParts = Split(FName, ".")
FF = MParts(0)
TT = MParts(1)
TT = UCase(TT)
If TT = "ML7" or TT="ML8" or TT="ML9" or TT="MLA" Then 'if milestone file
i = i + 1
FileName = f1.Name
FilePath = f1.Path
Set objmilestones(i) = GetObject(FilePath, "Milestones")
'Start using the new schedule object
With objmilestones(i)
.Activate
.SetDebugMode "Off"
dd = .GetCurrentDate
.SetCurrentDate DataDate
.Refresh
'-- Save the file -----
nFileHandleVariant = .Save
.Close
End With
End If
Next
Set fso = Nothing
'---
MsgBox "Done"

End Sub


To try this example:
Click here to download a Zip file (MilestonesVBExample5.Zip) containing the above VB code.

Visual Basic Automation Example #6

This is an example of using Visual Basic to scan a Milestones Professional schedule for specific symbol tags.

The Code:

'Public Sub Main()
Dim objmilestones As Object
Set objmilestones = GetObject("c:testsymboltags.mla")
With objmilestones
.Activate

'ABC
rownumber = .GetLineOfSymbolTag("ABC")
symbolnumber = .GetSymbolNumberOfSymbolTag("ABC")
.DisplayMessageBox "Found symbol ABC at row: " + Str(rownumber) + " Symbol: " + Str(symbolnumber)

rownumber = .GetLineOfSymbolTag("DEF")
symbolnumber = .GetSymbolNumberOfSymbolTag("DEF")
.DisplayMessageBox "Found symbol DEF at row: " + Str(rownumber) + " Symbol: " + Str(symbolnumber)

rownumber = .GetLineOfSymbolTag("KLM")
symbolnumber = .GetSymbolNumberOfSymbolTag("KLM")
.DisplayMessageBox "Found symbol KLM at row: " + Str(rownumber) + " Symbol: " + Str(symbolnumber)

rownumber = .GetLineOfSymbolTag("XYZ")
symbolnumber = .GetSymbolNumberOfSymbolTag("XYZ")
.DisplayMessageBox "Found symbol XYZ at row: " + Str(rownumber) + " Symbol: " + Str(symbolnumber)

.keepScheduleOpen

End With

End Sub

To try this example:
Click here to download a Zip file (MilestonesVBExample6.Zip) containing the above VB code.

Visual Basic Automation Example #7

This example shows how the SaveHTMLHyperlinkDrillDown method can be used
to generate a set of web pages.

The Code:

Public Sub Main()
Dim objmilestones As Object
'This example shows how the SaveHTMLHyperlinkDrillDown method can be used
' to generate a set of web pages.
' Along with this example, is a set of files which must be put into a folder
' named testhl on the C drive.

Set objmilestones = GetObject("c:testhltoplevel.mla")
With objmilestones
.Activate
.savehtmlhyperlinkdrilldown "C:testhltoplevel.htm"
.keepScheduleOpen
End With
End Sub

To try this example:

1 Click here to download a Zip file (MilestonesVBExample7.Zip) containing the above VB code and the Milestones Professional schedules needed for this example.

2 Create a folder on your C drive and name it TestHL

3 Extract the Milestones Professional schedules in the zip file to the new folder.

4 Run the program! (Be sure you have the latest Milestones Professional update)

Visual Basic Automation Example #8

Here's an example which illustrates many of Milestones Professional's OLE Automation methods.  It builds an outlined schedule, adds budget and actual cost values SmartColumns, and adds a DataGraph to represent it. Try this example
The Code: 
Sub main()
Set objMilestones = CreateObject("Milestones")
With objMilestones
'Start Milestones and Set to Use 20 Columns
.Activate
.Use20Columns

'Set Title
.SetTitle1 "Type 3 DataGraph Example - OLE Automation"
'Setup Symbols in the ToolBox
.SetToolboxSymbolProperty 1, "Type", 43
.SetToolboxSymbolProperty 1, "FillColor", 5
.SetToolboxSymbolProperty 2, "Type", 44
.SetToolboxSymbolProperty 2, "FillColor", 5
.SetToolboxSymbolProperty 3, "Type", 3
.SetToolboxSymbolProperty 3, "FillColor", 3
.SetToolboxSymbolProperty 4, "Type", 3
.SetToolboxSymbolProperty 4, "FillColor", 3
'Setup Horizontal Connectors in the Toolbox
.SetToolboxHorizontalConnectorProperty 1, "Type", 7
.SetToolboxHorizontalConnectorProperty 1, "FillColor", 5
.SetToolboxHorizontalConnectorProperty 2, "Type", 5
.SetToolboxHorizontalConnectorProperty 2, "FillColor", 3
.SetToolboxHorizontalConnectorProperty 2, "OutlineColor", 14
'Set Schedule Start and End Dates
.SetStartAndEndDates "1/1/2004", "12/31/2004"
'Remove Unneeded Columns and Rows From Template
.SetColumnWidth 1, 0
.SetColumnWidth 2, 0
.SetColumnWidth 3, 2.8
.SetLinesPerPage 8
'Put Text in Task Column
.PutCell 1, 3, "Project 1"
.PutCell 2, 3, "Task 1-1"
.PutCell 3, 3, "Task 1-2"
.PutCell 4, 3, "Task 1-3"
.PutCell 5, 3, "Project 2"
.PutCell 6, 3, "Task 2-1"
.PutCell 7, 3, "Task 2-2"
.PutCell 8, 3, "Task 2-3"
'Setup Outline Levels and Summary Bar Settings
.SetColumnProperty 3, "Indent", 0.3
.SetOutlineLevel 2, 2
.SetOutlineLevel 3, 2
.SetOutlineLevel 4, 2
.SetOutlineLevel 6, 2
.SetOutlineLevel 7, 2
.SetOutlineLevel 8, 2
.SetSummaryBarDisplay 2
'Add Symbols and Barlines and Remove Gridlines
.SetScheduleGridlinesAndShades 1, 0, 0, 0, 0, 0, 0
.SetScheduleVerticalGridlines 3, 0, 0, 0
.AddSymbol 2, "2/29/2004", 3, 2, 2
.AddSymbol 2, "9/17/2004", 4
.AddSymbol 3, "5/18/2004", 3, 2, 2
.AddSymbol 3, "9/20/2004", 4
.AddSymbol 4, "7/29/2004", 3, 2, 2
.AddSymbol 4, "11/4/2004", 4
.AddSymbol 6, "5/14/2004", 3, 2, 2
.AddSymbol 6, "10/30/2004", 4
.AddSymbol 7, "5/21/2004", 3, 2, 2
.AddSymbol 7, "10/25/2004", 4
.AddSymbol 8, "5/31/2004", 3, 2, 2
.AddSymbol 8, "10/25/2004", 4
'Insert Budget and Actual Cost Columns
.SetCustomColor 1, 128, 255, 128
.SetCustomColor 15, 255, 255, 128
.SetFontStyle 17, 0, -1, 18
.SetColumnProperty 11, "SmartColumn", "Values"
.SetColumnProperty 11, "ColumnBackgroundColor", 1
.SetColumnProperty 11, "ColumnHeadingLine1", "Budget"
.SetColumnProperty 11, "ColumnHeadingLine2", ""
.SetColumnProperty 11, "ColumnHorzTextAlign", 2
.SetColumnProperty 11, "DisplayColumnAsCurrency", 1
.SetColumnProperty 11, "HeadingBackgroundColor", 1
.SetColumnProperty 11, "NumberDecimals", 2
.SetColumnProperty 11, "Width", 1.23
.SetFontStyle 18, 0, -1, 18
.SetColumnProperty 12, "SmartColumn", "Values"
.SetColumnProperty 12, "ColumnBackgroundColor", 15
.SetColumnProperty 12, "ColumnHeadingLine1", "Actual"
.SetColumnProperty 12, "ColumnHeadingLine2", "Cost"
.SetColumnProperty 12, "ColumnHorzTextAlign", 2
.SetColumnProperty 12, "DisplayColumnAsCurrency", 1
.SetColumnProperty 12, "HeadingBackgroundColor", 15
.SetColumnProperty 12, "NumberDecimals", 2
.SetColumnProperty 12, "Width", 1.17
'Set Up ValueSets
.SetValueSetName 1, "Budget"
.SetValueSetProperty 1, "Type", 3
.SetValueSetProperty 1, "LineType", 1
.SetValueSetProperty 1, "BarPattern", 1
.SetValueSetProperty 1, "LineColor", 5
.SetValueSetProperty 1, "FillColor", 5
.SetValueSetProperty 1, "Show", "GraphOn"
.SetValueSetProperty 1, "Show", "GraphCumulativeOff"
.SetValueSetProperty 1, "Show", "CurrencyOn"
.SetValueSetProperty 1, "Show", "NumericOff"
.SetValueSetProperty 1, "Show", "GraphCumulativeOn"
.SetValueSetProperty 1, "Type3Column", 11
.SetValueSetName 2, "Actual Cost"
.SetValueSetProperty 2, "Type", 3
.SetValueSetProperty 2, "LineType", 1
.SetValueSetProperty 2, "BarPattern", 1
.SetValueSetProperty 2, "LineColor", 4
.SetValueSetProperty 2, "FillColor", 4
.SetValueSetProperty 2, "Show", "GraphOn"
.SetValueSetProperty 2, "Show", "GraphCumulativeOff"
.SetValueSetProperty 2, "Show", "CurrencyOn"
.SetValueSetProperty 2, "Show", "NumericOff"
.SetValueSetProperty 2, "Show", "GraphCumulativeOn"
.SetValueSetProperty 2, "Type3Column", 12
'Fill Budget and Actual Cost Columns
.PutCell 2, 11, 122
.PutCell 3, 11, 124
.PutCell 4, 11, 322
.PutCell 6, 11, 343
.PutCell 7, 11, 333
.PutCell 8, 11, 222
.PutCell 2, 12, 444
.PutCell 3, 12, 333
.PutCell 4, 12, 22
.PutCell 6, 12, 444
.PutCell 7, 12, 432
.PutCell 8, 12, 121
'Remove Legend and Replace with DataGraph
.SetLegendHeight 0
.SetDataGraphProperty 1, "ClearValueSets", 0
.SetDataGraphProperty 1, "Height", 1
.SetDataGraphProperty 1, "LineBar", "Bar"
.SetDataGraphProperty 1, "ShowGraph", "On"
.SetDataGraphProperty 1, "IncludeValueSet", 1
.SetDataGraphProperty 1, "IncludeValueSet", 2
.Refresh
.keepscheduleopen
End With
End Sub
Sub main()

Set objMilestones = CreateObject("Milestones")
With objMilestones
'Start Milestones
.Activate

'Set to Use 20 Columns
.Use20Columns

'Set Title
.SetTitle1 "Type 3 DataGraph Example - OLE Automation"

'Setup Symbols in the ToolBox
.SetToolboxSymbolProperty 1, "Type", 43
.SetToolboxSymbolProperty 1, "FillColor", 5
.SetToolboxSymbolProperty 2, "Type", 44
.SetToolboxSymbolProperty 2, "FillColor", 5
.SetToolboxSymbolProperty 3, "Type", 3
.SetToolboxSymbolProperty 3, "FillColor", 3
.SetToolboxSymbolProperty 4, "Type", 3
.SetToolboxSymbolProperty 4, "FillColor", 3

'Setup Horizontal Connectors in the Toolbox
.SetToolboxHorizontalConnectorProperty 1, "Type", 7
.SetToolboxHorizontalConnectorProperty 1, "FillColor", 5
.SetToolboxHorizontalConnectorProperty 2, "Type", 5
.SetToolboxHorizontalConnectorProperty 2, "FillColor", 3
.SetToolboxHorizontalConnectorProperty 2, "OutlineColor", 14

'Set Schedule Start and End Dates
.SetStartAndEndDates "1/1/2004", "12/31/2004"

'Remove Unneeded Columns and Rows From Template
.SetColumnWidth 1, 0
.SetColumnWidth 2, 0
.SetColumnWidth 3, 2.8
.SetLinesPerPage 8

'Put Text in Task Column
.PutCell 1, 3, "Project 1"
.PutCell 2, 3, "Task 1-1"
.PutCell 3, 3, "Task 1-2"
.PutCell 4, 3, "Task 1-3"
.PutCell 5, 3, "Project 2"
.PutCell 6, 3, "Task 2-1"
.PutCell 7, 3, "Task 2-2"
.PutCell 8, 3, "Task 2-3"

'Setup Outline Levels and Summary Bar Settings
.SetColumnProperty 3, "Indent", 0.3
.SetOutlineLevel 2, 2
.SetOutlineLevel 3, 2
.SetOutlineLevel 4, 2
.SetOutlineLevel 6, 2
.SetOutlineLevel 7, 2
.SetOutlineLevel 8, 2
.SetSummaryBarDisplay 2

'Add Symbols and Barlines and Remove Gridlines
.SetScheduleGridlinesAndShades 1, 0, 0, 0, 0, 0, 0
.SetScheduleVerticalGridlines 3, 0, 0, 0
.AddSymbol 2, "2/29/2004", 3, 2, 2
.AddSymbol 2, "9/17/2004", 4
.AddSymbol 3, "5/18/2004", 3, 2, 2
.AddSymbol 3, "9/20/2004", 4
.AddSymbol 4, "7/29/2004", 3, 2, 2
.AddSymbol 4, "11/4/2004", 4
.AddSymbol 6, "5/14/2004", 3, 2, 2
.AddSymbol 6, "10/30/2004", 4
.AddSymbol 7, "5/21/2004", 3, 2, 2
.AddSymbol 7, "10/25/2004", 4
.AddSymbol 8, "5/31/2004", 3, 2, 2
.AddSymbol 8, "10/25/2004", 4

'Insert Budget and Actual Cost Columns
.SetCustomColor 1, 128, 255, 128
.SetCustomColor 15, 255, 255, 128
.SetFontStyle 17, 0, -1, 18
.SetColumnProperty 11, "SmartColumn", "Values"
.SetColumnProperty 11, "ColumnBackgroundColor", 1
.SetColumnProperty 11, "ColumnHeadingLine1", "Budget"
.SetColumnProperty 11, "ColumnHeadingLine2", ""
.SetColumnProperty 11, "ColumnHorzTextAlign", 2
.SetColumnProperty 11, "DisplayColumnAsCurrency", 1
.SetColumnProperty 11, "HeadingBackgroundColor", 1
.SetColumnProperty 11, "NumberDecimals", 2
.SetColumnProperty 11, "Width", 1.23
.SetFontStyle 18, 0, -1, 18
.SetColumnProperty 12, "SmartColumn", "Values"
.SetColumnProperty 12, "ColumnBackgroundColor", 15
.SetColumnProperty 12, "ColumnHeadingLine1", "Actual"
.SetColumnProperty 12, "ColumnHeadingLine2", "Cost"
.SetColumnProperty 12, "ColumnHorzTextAlign", 2
.SetColumnProperty 12, "DisplayColumnAsCurrency", 1
.SetColumnProperty 12, "HeadingBackgroundColor", 15
.SetColumnProperty 12, "NumberDecimals", 2
.SetColumnProperty 12, "Width", 1.17

'Set Up ValueSets
.SetValueSetName 1, "Budget"
.SetValueSetProperty 1, "Type", 3
.SetValueSetProperty 1, "LineType", 1
.SetValueSetProperty 1, "BarPattern", 1
.SetValueSetProperty 1, "LineColor", 5
.SetValueSetProperty 1, "FillColor", 5
.SetValueSetProperty 1, "Show", "GraphOn"
.SetValueSetProperty 1, "Show", "GraphCumulativeOff"
.SetValueSetProperty 1, "Show", "CurrencyOn"
.SetValueSetProperty 1, "Show", "NumericOff"
.SetValueSetProperty 1, "Show", "GraphCumulativeOn"
.SetValueSetProperty 1, "Type3Column", 11
.SetValueSetName 2, "Actual Cost"
.SetValueSetProperty 2, "Type", 3
.SetValueSetProperty 2, "LineType", 1
.SetValueSetProperty 2, "BarPattern", 1
.SetValueSetProperty 2, "LineColor", 4
.SetValueSetProperty 2, "FillColor", 4
.SetValueSetProperty 2, "Show", "GraphOn"
.SetValueSetProperty 2, "Show", "GraphCumulativeOff"
.SetValueSetProperty 2, "Show", "CurrencyOn"
.SetValueSetProperty 2, "Show", "NumericOff"
.SetValueSetProperty 2, "Show", "GraphCumulativeOn"
.SetValueSetProperty 2, "Type3Column", 12

'Fill Budget and Actual Cost Columns
.PutCell 2, 11, 122
.PutCell 3, 11, 124
.PutCell 4, 11, 322
.PutCell 6, 11, 343
.PutCell 7, 11, 333
.PutCell 8, 11, 222
.PutCell 2, 12, 444
.PutCell 3, 12, 333
.PutCell 4, 12, 22
.PutCell 6, 12, 444
.PutCell 7, 12, 432
.PutCell 8, 12, 121

'Remove Legend and Replace with DataGraph
.SetLegendHeight 0
.SetDataGraphProperty 1, "ClearValueSets", 0
.SetDataGraphProperty 1, "Height", 1
.SetDataGraphProperty 1, "LineBar", "Bar"
.SetDataGraphProperty 1, "ShowGraph", "On"
.SetDataGraphProperty 1, "IncludeValueSet", 1
.SetDataGraphProperty 1, "IncludeValueSet", 2
.Refresh
.keepscheduleopen
End With
End Sub

To try this example:
Click here to download a Zip file (MilestonesVBExample8.Zip) containing the above VB code.

Visual Basic Automation Example #9

Using Visual Basic Automation and Windows Task Scheduler, send monthly, weekly, or even daily emails with information from a Milestones schedule. By changing parts of the following code, creating an .exe file using Microsoft Visual Basic 6.0, and setting up the Windows Task Scheduler, you can utilize this feature right away.
The Code:
Sub Main()

Dim objMilestones As Object

Dim CurrentDate1 As Variant

Dim StartDate1 As Variant

Dim EndDate1 As Variant

Dim PercentComplete1 As Integer

Dim objOutlook As Outlook.Application

Dim objItem As Outlook.MailItem

Dim syms As Integer

'Enter filename to use here:

Set objMilestones = GetObject("[MilestonesFilename]")

With objMilestones

.Activate    'Open Milestones

CurrentDate1 = .GetCurrentDate

StartDate1 = .GetSymbolProperty(1, 1, "Date")

syms = .GetNumberOfSymbolsInLine(1)

EndDate1 = .GetSymbolProperty(1, syms, "Date")

PercentComplete1 = .GetPercentComplete(1)

.Save

.Close

'You can get a lot of data from Milestones

'schedules using our Automation Methods.

'A list with a description of each method is available on the Help menu

End With

'Create Outlook object

Set objOutlook = CreateObject("Outlook.Application")

'Create a new e-mail message

Set objItem = objOutlook.CreateItem(olMailItem)

With objItem

'Set the recipient for the new email

.To = "username1@domain.com"

'Set multiple recipients as a cc

.CC = "username2@domain.com; username3@domain.com"

'Set the subject

.Subject = "Milestones Data"

'The following will create simple text used as the body

'for the email; "vbCrLf" creates a line break.

.Body = "Taskline as of " & CurrentDate1 & ":" & vbCrLf & " Start Date: " _

& StartDate1 & vbCrLf & " End Date: " & EndDate1 & vbCrLf & _

" Percent Complete: " & PercentComplete1 & "%" & vbCrLf & vbCrLf

'Send the Email

.Send

End With

End Sub

You can also get information from multiple schedules by repeating the code from the first Set objMilestones to the End With. Just change the file name and any different information you want to get from each file. You can also create the body of the e-mail using HTML in order to format your status updates in many different ways. To do this you would need to substitute the .Body method with .HTMLBody;

.HTMLBody = "You can also format using HTML"

To set up your task scheduler, go to Start | Settings | Control Panel | Scheduled Tasks | Add Task.  Click Next, browse for the .exe you created with VB6, and set the timing settings for how often you want this sent out. With this completed, updates will be sent automatically with no more effort on your part.

To try this example:
Click here to download a Zip file (MilestonesVBExample9.Zip) containing the above VB code.