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.
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)
To work with the contents of a task item, set or get the appropriate properties. These are the most widely useful properties:
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
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
18.226.133.35