Newbie question - A macro that will sort a list and then delete du

  • Thread starter Thread starter JeffG
  • Start date Start date
J

JeffG

I am new to Outlook macros and I could use a lot of help. I am using Office
2007 on an XP-SP3 machine. I am trying to write a little macro that will
sort a list and then delete duplicate lines. Thanks to Greg Maxey I can do
this in Word but, of course, that code doesn’t work in an Outlook message.
The code Greg shows is as follows:

Sub SortAndRemoveDuplicatesFromList()
Dim oPars As Paragraphs
Dim oPar As Paragraph
Dim myCol As New Collection
Set oPars = Selection.Paragraphs
If oPars.Count > 1 Then
Selection.Sort SortOrder:=wdSortOrderAscending
Else
MsgBox "There is no valid selection to sort"
Exit Sub
End If
For Each oPar In ActiveDocument.Range.Paragraphs
On Error Resume Next
myCol.Add oPar.Range.Text, oPar.Range.Text
If Err.Number = 457 Then oPar.Range.Delete
Next
End Sub

How can I get something similar that works in an Outlook message?

Thanks in advance for any help.
 
In Outlook see Items.Sort. Then it works the same: Use a VBA.Collection to
identify which Keys are the same (second argument of Coll.Add). You just
need to decide what property should tell you whether the item exists already
or not.

--
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 Wed, 18 Feb 2009 11:50:02 -0800 schrieb JeffG:
 
Back
Top