Interating throught a task list, respecting sort rules in the view

Status
Not open for further replies.
L

lberendsen

Hello,

I need to collect some tasks in a task folder to build a status e-mail.

Acctualy, I did it very well, but the sort classification are ignored.

How can i collect the tasks respecting the sort order?

Thank's in advance.

-
Here is the code:

Const C_ROOTITEM = 1

Dim oRoot As Outlook.Folder

Dim oFila As Outlook.Folder

Dim oEquipe As Outlook.Folder

Dim colInProgress As New Collection

Dim colWaiting As New Collection

Dim colNotStarted As New Collection

Dim oTask As taskItem

Dim oContact As ContactItem

Dim colDestinatários As New Collection

Dim colEmCópia As New Collection

Dim oNovoMail As MailItem

Dim strTo As String

Dim strCC As String

Dim strCorpo As String

Public Sub ReportAll()

' collect tasks and recipients

Set colInProgress = GetTasksByStatus(olTaskInProgress)

Set colNotStarted = GetTasksByStatus(olTaskNotStarted)

Set colWaiting = GetTasksByStatus(olTaskWaiting)

Set colDestinatários = GetRecipientsByJobTitle("Líder")

Set colEmCópia = GetRecipientsByJobTitle("Gerente")

' build a new e-mail

Set oNovoMail = Application.CreateItem(olMailItem)

oNovoMail.To = BuildRecipientList(colDestinatários)

oNovoMail.CC = BuildRecipientList(colEmCópia)

oNovoMail.Subject = "Fila de Validações"

'@@

'@@ e-mail body

'@@

strCorpo = ""

' Introdução

strCorpo = "Pessoal,"

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "Segue a fila da validações"

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "Caso tenham alguma urgência, comuniquem-me

imediatamente que eu repriorizo na hora"

strCorpo = strCorpo + Chr(13)

' to-do itens

If colNotStarted.Count > 0 Then

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "A REVISAR"

strCorpo = strCorpo + Chr(13) + Chr(13)

For Each oTask In colNotStarted

strCorpo = strCorpo + oTask.Subject & " (" & oTask.ContactNames

& ")" & Chr(13)

Next

End If

' on going itens

If colInProgress.Count > 0 Then

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "EM REVISÃO"

strCorpo = strCorpo + Chr(13) + Chr(13)

For Each oTask In colInProgress

strCorpo = strCorpo + VerboseTask(oTask) & Chr(13)

Next

End If

' waiting itens

If colWaiting.Count > 0 Then

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "AGUARDANDO RETORNO"

strCorpo = strCorpo + Chr(13) + Chr(13)

For Each oTask In colWaiting

strCorpo = strCorpo + VerboseTask(oTask) & Chr(13)

Next

End If

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "Obrigado,"

strCorpo = strCorpo + Chr(13)

strCorpo = strCorpo + "Lorenzo"

oNovoMail.Body = strCorpo

'@@

'@@ show the e-mail to send

'@@

oNovoMail.Recipients.ResolveAll

oNovoMail.Display

End Sub

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'

' TOOLS FUNCTIONS

'

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Public Sub GotoFilaNatura()

' Abre a fila Natura

Dim oFila As Outlook.Folder

Call SetRoot

Set oFila = GetFolder("FilaNatura", oRoot)

oFila.Display

End Sub

Public Sub SetRoot()

' Retorna a raiz da pasta local.

' Esta função garante que a aplicação trabalhe sempre com uma pasta específica

Dim colStores As Outlook.Stores

Dim oStore As Outlook.Store

Dim oTempRoot As Outlook.Folder

On Error Resume Next

Set colStores = Application.Session.Stores

For Each oStore In colStores

Set oTempRoot = oStore.GetRootFolder

If oTempRoot.Name = "Personal Folders" Then

Set oRoot = oTempRoot

End If

Next

End Sub

Public Function GetFolder(ByVal folderName As String, oBase As

Outlook.Folder) As Outlook.Folder

' Passando um nome, retorna um ponteiro para o folder com o mesmo nome

' Em qualquer nível de profundidade.

Dim folders As Outlook.folders

Dim Folder As Outlook.Folder

Dim foldercount As Integer

On Error Resume Next

Set folders = oBase.folders

foldercount = folders.Count

'Check if there are any folders below oFolder

If foldercount Then

For Each Folder In folders

If Folder.Name = folderName Then

Set GetFolder = Folder

Else

GetFolder folderName, Folder

End If

Next

End If

End Function

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'

' QUERY FUNCTIONS

'

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Public Function GetTasksByStatus(ByVal targetStatus As Variant) As Collection

' Retorna todos os itens da fila que tenham um stats específico

Dim colNewCollection As New Collection

Dim taskIndex As taskItem

' Obtém os repositórios

Call SetRoot

Set oFila = GetFolder("FilaNatura", oRoot)

Set colNewCollection = Nothing

For Each taskIndex In oFila.Items

If taskIndex.Status = targetStatus Then

colNewCollection.Add taskIndex

End If

Next

Set GetTasksByStatus = colNewCollection

End Function

Public Function GetRecipientsByJobTitle(ByVal targetRole As Variant) As

Collection

' Retorna todos as pessoas que tenham um job title específico

Dim colNewCollection As New Collection

Dim contactIndex As ContactItem

' Obtém os repositórios

Call SetRoot

Set oEquipe = GetFolder("EquipeNatura", oRoot)

Set colNewCollection = Nothing

For Each contactIndex In oEquipe.Items

If contactIndex.JobTitle = targetRole Then

colNewCollection.Add contactIndex

End If

Next

Set GetRecipientsByJobTitle = colNewCollection

End Function

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'

' TRANSFORMATION FUNCTIONS

'

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Public Function BuildRecipientList(colRecipientsList As Collection) As String

' Coloca uma lista de pessoas em uma string separada por ponto-e-vírgula

Dim strTo As String

Dim contactIndex As ContactItem

strTo = ""

For Each contactIndex In colRecipientsList

strTo = strTo + contactIndex.Email1DisplayName

strTo = strTo + " ; "

Next

BuildRecipientList = strTo

End Function

Public Function VerboseTask(aTask As taskItem) As String

' Representa uma task em uma string

Dim strResponsável As String

Dim strNome As String

strNome = aTask.Subject

strResponsável = aTask.ContactNames

VerboseTask = strNome & " (" & strResponsável & ")"

End Function
 
That's a lot of code to make someone look through, but I don't see any place

in it that you've called the Items.Sort method.

Sue Mosher

"lberendsen" <lberendsen> wrote in message

news:177368B2-67AF-4A29-A872-DEC3B4A8EA72@microsoft.com...
> Hello,

> I need to collect some tasks in a task folder to build a status e-mail.
> Acctualy, I did it very well, but the sort classification are ignored.

> How can i collect the tasks respecting the sort order?

> Thank's in advance.

> -
> Here is the code:

> Const C_ROOTITEM = 1

> Dim oRoot As Outlook.Folder
> Dim oFila As Outlook.Folder
> Dim oEquipe As Outlook.Folder

> Dim colInProgress As New Collection
> Dim colWaiting As New Collection
> Dim colNotStarted As New Collection
> Dim oTask As taskItem

> Dim oContact As ContactItem
> Dim colDestinatários As New Collection
> Dim colEmCópia As New Collection

> Dim oNovoMail As MailItem
> Dim strTo As String
> Dim strCC As String
> Dim strCorpo As String

> Public Sub ReportAll()

> ' collect tasks and recipients
> Set colInProgress = GetTasksByStatus(olTaskInProgress)
> Set colNotStarted = GetTasksByStatus(olTaskNotStarted)
> Set colWaiting = GetTasksByStatus(olTaskWaiting)
> Set colDestinatários = GetRecipientsByJobTitle("Líder")
> Set colEmCópia = GetRecipientsByJobTitle("Gerente")

> ' build a new e-mail
> Set oNovoMail = Application.CreateItem(olMailItem)
> oNovoMail.To = BuildRecipientList(colDestinatários)
> oNovoMail.CC = BuildRecipientList(colEmCópia)
> oNovoMail.Subject = "Fila de Validações"

> '@@
> '@@ e-mail body
> '@@

> strCorpo = ""

> ' Introdução
> strCorpo = "Pessoal,"
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "Segue a fila da validações"
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "Caso tenham alguma urgência, comuniquem-me
> imediatamente que eu repriorizo na hora"
> strCorpo = strCorpo + Chr(13)

> ' to-do itens
> If colNotStarted.Count > 0 Then
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "A REVISAR"
> strCorpo = strCorpo + Chr(13) + Chr(13)
> For Each oTask In colNotStarted
> strCorpo = strCorpo + oTask.Subject & " (" & oTask.ContactNames
> & ")" & Chr(13)
> Next
> End If

> ' on going itens
> If colInProgress.Count > 0 Then
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "EM REVISÃO"
> strCorpo = strCorpo + Chr(13) + Chr(13)
> For Each oTask In colInProgress
> strCorpo = strCorpo + VerboseTask(oTask) & Chr(13)
> Next
> End If

> ' waiting itens
> If colWaiting.Count > 0 Then
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "AGUARDANDO RETORNO"
> strCorpo = strCorpo + Chr(13) + Chr(13)
> For Each oTask In colWaiting
> strCorpo = strCorpo + VerboseTask(oTask) & Chr(13)
> Next
> End If

> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "Obrigado,"
> strCorpo = strCorpo + Chr(13)
> strCorpo = strCorpo + "Lorenzo"

> oNovoMail.Body = strCorpo

> '@@
> '@@ show the e-mail to send
> '@@

> oNovoMail.Recipients.ResolveAll
> oNovoMail.Display

> End Sub

> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '
> ' TOOLS FUNCTIONS
> '
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

> Public Sub GotoFilaNatura()
> ' Abre a fila Natura

> Dim oFila As Outlook.Folder

> Call SetRoot
> Set oFila = GetFolder("FilaNatura", oRoot)

> oFila.Display

> End Sub

> Public Sub SetRoot()
> ' Retorna a raiz da pasta local.
> ' Esta função garante que a aplicação trabalhe sempre com uma pasta
> específica

> Dim colStores As Outlook.Stores
> Dim oStore As Outlook.Store
> Dim oTempRoot As Outlook.Folder

> On Error Resume Next
> Set colStores = Application.Session.Stores
> For Each oStore In colStores
> Set oTempRoot = oStore.GetRootFolder
> If oTempRoot.Name = "Personal Folders" Then
> Set oRoot = oTempRoot
> End If
> Next

> End Sub

> Public Function GetFolder(ByVal folderName As String, oBase As
> Outlook.Folder) As Outlook.Folder
> ' Passando um nome, retorna um ponteiro para o folder com o mesmo nome
> ' Em qualquer nível de profundidade.

> Dim folders As Outlook.folders
> Dim Folder As Outlook.Folder
> Dim foldercount As Integer

> On Error Resume Next
> Set folders = oBase.folders
> foldercount = folders.Count

> 'Check if there are any folders below oFolder
> If foldercount Then
> For Each Folder In folders
> If Folder.Name = folderName Then
> Set GetFolder = Folder
> Else
> GetFolder folderName, Folder
> End If
> Next
> End If

> End Function

> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '
> ' QUERY FUNCTIONS
> '
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

> Public Function GetTasksByStatus(ByVal targetStatus As Variant) As
> Collection
> ' Retorna todos os itens da fila que tenham um stats específico

> Dim colNewCollection As New Collection
> Dim taskIndex As taskItem

> ' Obtém os repositórios
> Call SetRoot
> Set oFila = GetFolder("FilaNatura", oRoot)

> Set colNewCollection = Nothing
> For Each taskIndex In oFila.Items
> If taskIndex.Status = targetStatus Then
> colNewCollection.Add taskIndex
> End If
> Next

> Set GetTasksByStatus = colNewCollection

> End Function

> Public Function GetRecipientsByJobTitle(ByVal targetRole As Variant) As
> Collection
> ' Retorna todos as pessoas que tenham um job title específico

> Dim colNewCollection As New Collection
> Dim contactIndex As ContactItem

> ' Obtém os repositórios
> Call SetRoot
> Set oEquipe = GetFolder("EquipeNatura", oRoot)

> Set colNewCollection = Nothing
> For Each contactIndex In oEquipe.Items
> If contactIndex.JobTitle = targetRole Then
> colNewCollection.Add contactIndex
> End If
> Next

> Set GetRecipientsByJobTitle = colNewCollection

> End Function

> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '
> ' TRANSFORMATION FUNCTIONS
> '
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

> Public Function BuildRecipientList(colRecipientsList As Collection) As
> String
> ' Coloca uma lista de pessoas em uma string separada por ponto-e-vírgula

> Dim strTo As String
> Dim contactIndex As ContactItem

> strTo = ""
> For Each contactIndex In colRecipientsList
> strTo = strTo + contactIndex.Email1DisplayName
> strTo = strTo + " ; "
> Next

> BuildRecipientList = strTo

> End Function

> Public Function VerboseTask(aTask As taskItem) As String
> ' Representa uma task em uma string

> Dim strResponsável As String
> Dim strNome As String

> strNome = aTask.Subject
> strResponsável = aTask.ContactNames

> VerboseTask = strNome & " (" & strResponsável & ")"

> End Function
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
D Copy Appointment Body to Task Body Outlook VBA and Custom Forms 0
K Daily Task List Minimized Cannot Display Using Outlook 5
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 4
S Outlook 2016 Understand and customize prepended behavior of recurring task Using Outlook 0
B Outlook 365 Populate Outlook Task UDFs from a UDF text string Outlook VBA and Custom Forms 2
K Multiple copies of task being created Using Outlook 2
P Short Date Format when typing in a task Using Outlook 2
C Outlook 2013 Task Recurrence - Third Friday After the Second Tuesday Using Outlook 2
P Task display now leaves little room for notes Using Outlook 10
C-S-R How to clear an Outlook (To Do) Task Flag? Using Outlook 8
G Event when creating task from mailitem Outlook VBA and Custom Forms 2
P Changing the font that the task view shows Using Outlook 5
D How To Combine Share Task Folders in just one Folder Using Outlook 0
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 2
G Arggh, weakness of reminder for every Task recurrence Using Outlook 0
P Can't paste an image into a task Using Outlook 3
F Validation on custom task form after task acceptance Outlook VBA and Custom Forms 1
J Office 365 erased all of my task views Using Outlook 3
T Report For Task Recurrance Outlook VBA and Custom Forms 4
E Can't accept or decline task (no button appears) Using Outlook 2
Z VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
Z Task Filter Not Working When I add too many criteria Using Outlook 0
X If you change expiration date of repeated task it dupplicates Using Outlook 1
Z How to show concatenated categories in list task view? Using Outlook 2
Z VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
E To convert imported data to custom fields in Task list Outlook VBA and Custom Forms 1
I Help with dates in task list. Using Outlook 5
Y Outlook Task View - Table Format - Customize Reminder Time to Drop-Down Selection Using Outlook 2
M Daily Task List Minimized Cannot Display Using Outlook 2
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
P Add a contact to the New Task in Outlook 2016 Using Outlook 2
S Codes for "Mark Complete" the task Outlook VBA and Custom Forms 2
W Deleting Sent Task Email, Deletes the task from my list Using Outlook 1
K Task priority modification Using Outlook 4
F Search folder for tasks in all task folders Using Outlook 1
JohnViuf Export task list view settings to other pc Outlook VBA and Custom Forms 16
V Changing default date for task follow-up buttons Using Outlook 2
K outlook workflow: automated task generation Outlook VBA and Custom Forms 4
U HTML Task Alternate Home Page View Control Using Outlook 3
F How to assign a task to a public task folder? Using Outlook 1
J Marketing task MS BCM BCM (Business Contact Manager) 10
copperberry How to view all tasks across task folders Using Outlook 3
P Task Categories Using Outlook 2
P Run Time Error 91 when linking contact to task in VBA Outlook VBA and Custom Forms 1
L Email to task without changin formatting Outlook VBA and Custom Forms 16
S BCM Project Task Order BCM (Business Contact Manager) 1
P Custom form reverts from task Outlook VBA and Custom Forms 1
evdbogaard How to dock the Styles Task Pane in the e-mail editing window? Outlook VBA and Custom Forms 1
S Default Font in body of Task Using Outlook 0

Similar threads

Back
Top