|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. Try this example|
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]")
.Activate 'Open Milestones
CurrentDate1 = .GetCurrentDate
StartDate1 = .GetSymbolProperty(1, 1, "Date")
syms = .GetNumberOfSymbolsInLine(1)
EndDate1 = .GetSymbolProperty(1, syms, "Date")
PercentComplete1 = .GetPercentComplete(1)
'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
'Create Outlook object
Set objOutlook = CreateObject("Outlook.Application")
'Create a new e-mail message
Set objItem = objOutlook.CreateItem(olMailItem)
'Set the recipient for the new email
.To = "email@example.com"
'Set multiple recipients as a cc
.CC = "firstname.lastname@example.org; email@example.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
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 = "<HTML><BODY><B>You can also format using HTML</B></Body></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.|