26.6. Working with Tasks and Task Requests

You may also be able to save time and effort by using VBA to automate tasks and task requests. This section shows you how to create a task, work with the contents of a task item, and send a task request.

26.6.1. Creating a Task

To create a new task item, use the CreateItem method of the Application object and specify olTaskItem for the ItemType argument. The following example creates a TaskItem object variable named myTask and assigns to it a new task item:

Dim myTask As TaskItem
Set myTask = Application.CreateItem(ItemType:=olTaskItem)

26.6.2. Working with the Contents of a Task Item

To work with the contents of a task item, set or get the appropriate properties. These are the most widely useful properties:

PropertyExplanation
SubjectSubject of the task.
BodyBody text of the task.
StartStart time of the task.
DueDateThe due date of the task.
ImportanceThe importance of the task. Set it to olImportanceHigh, olImportanceNormal, or olImportanceLow.
StatusThe status of the task: olTaskNotStarted, olTaskWaiting, olTaskDeferred, olTaskInProgress, or olTaskComplete.
PercentCompleteThe percentage of the task completed.
CompaniesThe companies associated with the task.
BillingInformationThe company or department to bill for the task.

The following example creates a TaskItem object variable named myTask and assigns to it a new task item. It then sets the subject and body of the task, specifies a due date, sets the status to olTaskInProgress and the percentage complete to 10, specifies the company involved and who to bill, sets the importance to High, and then saves the task:

Dim myTask As TaskItem
Set myTask = Application.CreateItem(ItemType:=olTaskItem)
With myTask
    .Subject = "Create a business plan"
    .Body = "The business plan must cover the next four years." & _
        vbCr & vbCr & "It must provide a detailed budget, " & _
        "staffing projections, and a cost/benefit analysis."
    .DueDate = Str(Date +28)
    .Status = olTaskInProgress
    .PercentComplete = 10
    .Companies = "Acme Polyglot Industrialists"
    .BillingInformation = "Sales & Marketing"
    .Importance = olImportanceHigh
    .Save
End With

26.6.3. Assigning a Task to a Colleague

To assign a task to a colleague, use the Assign method of the TaskItem object, and then use the Add method of the Recipients collection to add one or more recipients. You can then use the Send method to send the task to your colleague.

The following example creates a task, uses the Assign method to indicate that it will be assigned, specifies a recipient, and sends the task:

Dim myTaskAssignment As TaskItem
Set myTaskAssignment = Application.CreateItem(ItemType:=olTaskItem)
With myTaskAssignment
    .Assign
    .Recipients.Add Name:="Peter Nagelly"
    .Subject = "Buy Bagels for Dress-Down/Eat-Up Day"

.Body = "It's your turn to get the bagels on Friday."
    .Body = .Body & vbCr & vbCr & "Remember: No donuts AT ALL."
    .DueDate = Str(Date +3)
    .Send
End With

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.133.35