Can't sort Outlook Personal Folder using Items.Sort 
Author Message
 Can't sort Outlook Personal Folder using Items.Sort

Objective is to flag possibly duplicate messages in an Outlook Personal
folder (for which MS's "Threadcompressor" code example is not suitable).

Attempts to achieve this by sorting items into a suitable order (e.g.
subject, date), then scanning for duplicates are frustrated because the
Item.Sort doesn't seem to work.

The following Outlook VBA sample code attempts to sort mail items
in "Personal Folder (Test)", subfolder "Test" - but doesn't seem to
work !

Sub Main()

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders

Debug.Print Chr(13); "Outlook MAPI Folder Item Sort test - "; Date; Chr
(13)

' Look for "Test" folder, "Test" sub-folder
For Each objFolder In myNameSpace.Folders

 If objFolder.Name = "Personal Folders (Test)" Then

  For Each objSubFolder In objFolder.Folders

   If objSubFolder.Name = "Test" Then

    If objSubFolder.Items.Count >= 4 Then

     objSubFolder.Items.Sort "[Subject]", True

     Debug.Print "    objFolder.Items.Sort ""[Subject]"", True"; Chr
(13); " 1", objSubFolder.Items(1).Subject; Chr(13); " 2",
objSubFolder.Items(2).Subject; Chr(13); " 3", objSubFolder.Items
(3).Subject, Chr(13); " 4", objSubFolder.Items(4).Subject; Chr(13)

     objSubFolder.Items.Sort "[Subject]", False

     Debug.Print "    objFolder.Items.Sort ""[Subject]"", False"; Chr
(13); " 1", objSubFolder.Items(1).Subject; Chr(13); " 2",
objSubFolder.Items(2).Subject; Chr(13); " 3", objSubFolder.Items
(3).Subject, Chr(13); " 4", objSubFolder.Items(4).Subject; Chr(13)

    End If

   End if

  Next objSubFolder

 End If

Next objFolder

End Sub

Sent via Deja.com
http://www.*-*-*.com/



Sat, 28 Jun 2003 17:54:39 GMT  
 Can't sort Outlook Personal Folder using Items.Sort
Can yoiu be more specific about what isn't working? Did you actually get the
right MAPIFolder object? Or is the problem that the sorting isn't working?

--
Sue Mosher, Outlook MVP
Author of
     Teach Yourself Microsoft Outlook 2000 Programming in 24 Hours
     Microsoft Outlook 2000 E-mail and Fax Guide
Outlook and Exchange solutions at http://www.slipstick.com


Quote:
> Objective is to flag possibly duplicate messages in an Outlook Personal
> folder (for which MS's "Threadcompressor" code example is not suitable).

> Attempts to achieve this by sorting items into a suitable order (e.g.
> subject, date), then scanning for duplicates are frustrated because the
> Item.Sort doesn't seem to work.

> The following Outlook VBA sample code attempts to sort mail items
> in "Personal Folder (Test)", subfolder "Test" - but doesn't seem to
> work !

> Sub Main()

> Set myOlApp = CreateObject("Outlook.Application")
> Set myNameSpace = myOlApp.GetNamespace("MAPI")
> Set myFolders = myNameSpace.Folders

> Debug.Print Chr(13); "Outlook MAPI Folder Item Sort test - "; Date; Chr
> (13)

> ' Look for "Test" folder, "Test" sub-folder
> For Each objFolder In myNameSpace.Folders

>  If objFolder.Name = "Personal Folders (Test)" Then

>   For Each objSubFolder In objFolder.Folders

>    If objSubFolder.Name = "Test" Then

>     If objSubFolder.Items.Count >= 4 Then

>      objSubFolder.Items.Sort "[Subject]", True

>      Debug.Print "    objFolder.Items.Sort ""[Subject]"", True"; Chr
> (13); " 1", objSubFolder.Items(1).Subject; Chr(13); " 2",
> objSubFolder.Items(2).Subject; Chr(13); " 3", objSubFolder.Items
> (3).Subject, Chr(13); " 4", objSubFolder.Items(4).Subject; Chr(13)

>      objSubFolder.Items.Sort "[Subject]", False

>      Debug.Print "    objFolder.Items.Sort ""[Subject]"", False"; Chr
> (13); " 1", objSubFolder.Items(1).Subject; Chr(13); " 2",
> objSubFolder.Items(2).Subject; Chr(13); " 3", objSubFolder.Items
> (3).Subject, Chr(13); " 4", objSubFolder.Items(4).Subject; Chr(13)

>     End If

>    End if

>   Next objSubFolder

>  End If

> Next objFolder

> End Sub

> Sent via Deja.com
> http://www.deja.com/



Sat, 28 Jun 2003 20:45:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Can't sorting Mail Items in Outlook subfolder using VBA

2. using sort functionality to walk through items in folder

3. Items.Sort NOT Sorting????

4. Get items from Listview sorted with API:s in sorted order

5. Sort order - Edit Filter Sort or Quick Sort

6. Unread Items in Public Folders like in personal Folders

7. Listbox/Combobox - .Sorted=True doesn't sort ItemData

8. Outlook Empy 'Deleted Items Folder'

9. Retrieve Selected Explorer Items Using Current Sort

10. Can't get Sorted Recordset using Query

11. Using Hyperlinks to Access Outlook Folders and Items

12. Help Copy Public Folder Calander Items to Personal Calendar(code sample)

 

 
Powered by phpBB® Forum Software