Add/Update Outlook task

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
 
B

Bruno Campanini

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
 
K

Ken Slovak - [MVP - Outlook]

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
 
M

Michael Bauer [MVP - Outlook]

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:
 

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