Add/Update Outlook task

  • Thread starter Thread starter CBenac
  • Start date Start date
C

CBenac

OUTLOOK

I'm looking for VBA code to do the following:

1.Search for a task by [Subject] and add it if it doesn't exist
2. Add (append) text to the body of the task referecend above.

Thanks
 
CBenac said:
OUTLOOK

I'm looking for VBA code to do the following:

1.Search for a task by [Subject] and add it if it doesn't exist
2. Add (append) text to the body of the task referecend above.

Thanks

====================================
Public Sub SearchAndAdd()
Dim MyTask As Object, i As Object, k As Boolean

Set MyTask = Application.Session.GetDefaultFolder(olFolderTasks)

For Each i In MyTask.Items
If i.Subject = "DDD" Then
k = True
Exit For
End If
Next

If Not k Then
With MyTask.Items.Add
.Subject = "DDD"
.Body = "Text"
.Save
End With
End If

End Sub
=====================================

Bruno
 
For a less brute force approach:

Function GetTaskWithSubject(testSubject As String, appendText As String) As
Outlook.TaskItem
Dim oTask As Outlook.TaskItem
Dim colItems As Outlook.Items
Dim oFolder As Outlook.MAPIFolder

Set oFolder = Application.Session.GetDefaultFolder(olFolderTasks)
Set colItems = oFolder.Items

Set oTask = colItems.Find("[Subject] ='" & testSubject & "'")

If oTask Is Nothing Then
Set oTask = colItems.Add(olTaskItem)
oTask.Subject = testSubject
End If

oTask.Body = oTask.Body & appendText

Set GetTaskWithSubject = oTask
End Function




Bruno Campanini said:
CBenac said:
OUTLOOK

I'm looking for VBA code to do the following:

1.Search for a task by [Subject] and add it if it doesn't exist
2. Add (append) text to the body of the task referecend above.

Thanks

====================================
Public Sub SearchAndAdd()
Dim MyTask As Object, i As Object, k As Boolean

Set MyTask = Application.Session.GetDefaultFolder(olFolderTasks)

For Each i In MyTask.Items
If i.Subject = "DDD" Then
k = True
Exit For
End If
Next

If Not k Then
With MyTask.Items.Add
.Subject = "DDD"
.Body = "Text"
.Save
End With
End If

End Sub
=====================================

Bruno
 
See the VBA help file for the Filter or Restrict function. With that you can
search for the subject.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 5 Feb 2009 18:36:03 -0800 schrieb CBenac:
 
Back
Top