Help!

Newbie question - A macro that will sort a list and then d..

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA RSS
Next:  Calendar Invite/Recipient List Problem  
Author Message
JeffG
External


Since: Feb 18, 2009
Posts: 1



PostPosted: Wed Feb 18, 2009 11:50 am    Post subject: Newbie question - A macro that will sort a list and then delete du
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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.
Back to top
Michael Bauer [MVP - Outl
External


Since: Aug 04, 2006
Posts: 647



PostPosted: Sat Feb 21, 2009 6:10 am    Post subject: Re: Newbie question - A macro that will sort a list and then delete du [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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:

> 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.
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum