Assigning a Calendar to a Task via VBA

P

Peter Rooney

I am writing a macro to go through every task in my plan and assign one of 19
calendars to it, depending on what it finds in the resource names field.

I'm doing this with a Case statement, which works fine in terms of
identifying the resource, I just can't assign the calendar.

Here's what I have so far:

Sub AssignCalendarsToTasks()
Dim TaskCounter As Integer
Dim ThisTasksResource As String
SelectSheet
For TaskCounter = 1 To ActiveSelection.Tasks.Count
ThisTasksResource = ActiveSelection.Tasks(TaskCounter).ResourceNames
MsgBox (ActiveSelection.Tasks(TaskCounter).ID & " - " &
ThisTasksResource)
Select Case ThisTasksResource
Case "Graham Tatton"
XX
activeselection.tasks(taskcounter).setfield(pjtaskcalendar,"01a-Graham
Tatton")
Case "Min Patel"
SetTaskField Field:="Task Calendar", Value:="01b-Min Patel",
AllSelectedTasks:=False

Case etc etc

Case Else
'MsgBox ("Somebody Else - " & ThisTasksResource)
SetTaskField Field:="Task Calendar", Value:="Standard",
AllSelectedTasks:=False
End Select
'Next
End Sub

It's the line beginning with XX that's giving me trouble.
"O1a-Graham Tatton" is the name of the calendar I want to apply if the first
case statement is met.

The code in the Case for "Min Patel" works, but only if the task row is
physically selected, which I don't want to have to do.

Can anyone help?

Thanks in advance

Pete
 
J

Jan De Messemaeker

Hi Peter,

First a remark. I strictly only use selections or fields when I have to set
fonts.
Otherwise one uses the objects directly
For each job in activeproject.tasks fror instance

And you set a calendar through

job.calendar="My Special One"

HTH
 
P

Peter Rooney

Jan,

Thanks VERY much!

These things might seem like childs' play to you, but when you don't know,
you just DON'T know!

Regards

Pete
 
J

Jan De Messemaeker

Hi Peter,

To tell you the truth, I didn't know.
As always, ib VB Editor, I clicked Object browser and asked for Calendar (it
had to be somethong like that)
The help told me the rest.
Greetings,
 
P

Peter Rooney

Well, thanks anyway!

I'll get back to "VBA to display a specific graph" now..!

Cheers

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top