Article ID: 180994
Article Last Modified on 1/22/2007
176476 OFF: Office Assistant Not Answering Visual Basic Questions
Sub Macro1()
'This macro displays the first task name, and then sets the Text1
'field for that task to the string Hello World.
'This line displays a message box that contains the Task Name
'of the first task.
MsgBox ActiveProject.Tasks(1).Name
'This line sets the value of the Name field to the
'the string Hello World.
ActiveProject.Tasks(1).Name = "Hello World"
'This line sets the value of the Text1 field to the
'the value of the Name field, which is Hello World.
ActiveProject.Tasks(1).Text1 = ActiveProject.Tasks(1).Name
End Sub
Sub Macro2()
'This macro loops through all of the tasks in the active project
'and displays the name of each task.
For Each x In ActiveProject.Tasks
MsgBox x.Name
Next x
End Sub
Sub Macro3()
'This macro loops through all of the tasks in the active project
' and sets the Text1 field to the string Hello World.
For Each x In ActiveProject.Tasks
x.Text1 = "Hello World"
Next x
End Sub
Sub Macro4()
'This macro loops through all tasks and adds "Hello " to each task name
'it also skips summary tasks and blank rows.
Dim abbr As String
abbr = "Hello"
For Each t In ActiveProject.Tasks
If Not (t Is Nothing) Then
If Not t.Summary Then
t.Name = abbr & ": " & t.Name
End If
End If
Next t
End Sub
Sub Macro5()
'calendarflag is a variable that will be used as a flag
'to test if the 24 Hours calendar exists in the project.
calendarflag = 0
'This loop tests to see if the 24 Hours calendar exists
'in the ActiveProject.
For Each C In ActiveProject.BaseCalendars
If C.Name = "24 Hours" Then calendarflag = 1
Next C
'The next line tests if calendarflag is set to 1; if not,
'then it copies the 24 hour calendar into the ActiveProject.
If calendarflag = 0 Then
'This line copies the 24 hour calendar from the Global
'template into the ActiveProject.
OrganizerMoveItem Type:=5, FileName:="GLOBAL.MPT", _
ToFileName:=ActiveProject.Name, Name:="24 Hours"
End If
'This line changes the first resources Base Calendar
'to be the 24 Hours calendar.
ActiveProject.Resources(1).BaseCalendar = "24 hours"
End Sub
Sub Macro6()
'This macro sets non-working days and alters the working time
'for a resource calendar.
'This line sets 1/6/98 through 1/8/98 to be non-working.
ResourceCalendarEditDays Projectname:=ActiveProject.Name, _
ResourceName:="R1", StartDate:="1/6/98 12:00 AM", _
EndDate:="1/8/98 12:00 AM", Working:=False
'This line changes the working time for the dates 1/12/98
'through 1/16/98. The new working time is from 7:00 AM to 12:00 PM
'and 1:00 PM to 7:00 PM.
ResourceCalendarEditDays Projectname:=ActiveProject.Name, _
ResourceName:="R1", StartDate:="1/12/98 12:00 AM", _
EndDate:="1/16/98 12:00 AM", Working:=True, Default:=False, _
From1:="7:00 AM", To1:="12:00 PM", From2:="1:00 PM", To2:="7:00 PM"
End Sub
Sub Macro7()
'This macro adds a pay rate on a cost table, and then displays the
'location where it was added.
'This line adds the pay rate on Cost Rate Table C for 1/15/98 at
'3.00/hour for the first resource.
z=activeProject.Resources(1).CostRateTables("c"). _
PayRates.Add("1/15/1998", "3.00/h")
'This line displays a message box containing the position where in the
'collection the rate is added. Payrates are inserted into the
'collection based on the date. So, if another rate is added with an
'earlier date than an existing rate, the index for the existing rate
'would be incremented one higher.
MsgBox z
End Sub
Sub Macro8()
'This Macro assigns a resource to a task in two different ways.
'This line assigns the first resource on the Resource Sheet to the
'first task.
ActiveProject.Tasks(1).Assignments.Add , 1
'This line assigns the second resource on the resource sheet to the
'second task.
ActiveProject.Resources(2).Assignments.Add 2
End Sub
Sub Macro9()
'The following line sets the Actual Work field for Task 1 to 4h on
'1/15/98.
ActiveProject.Tasks(1).TimeScaleData(StartDate:= _
"1/15/98 12:00 AM", EndDate:="1/16/98 12:00 AM", _
Type:=pjTaskTimescaledActualWork, TimeScaleUnit:=4, _
Count:=1).Item(1).Value = "4h"
'The following line sets the Actual Work field for the resource
'assigned to task 1 to 2h on 1/16/98.
ActiveProject.Tasks(1).Assignments(1). _
TimeScaleData(StartDate:="1/16/98 12:00 AM", _
EndDate:="1/17/98 12:00 AM", Type:=10, TimeScaleUnit:=4, _
Count:=1).Item(1).Value = "2"
End Sub
Keywords: kbdtacode kbinfo kbmacro KB180994