A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

macro that checks if email is duplicate



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4  
Old November 22nd 06, 05:51 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default macro that checks if email is duplicate


The loops are the same in VB and VBA, maybe you're talking about VB.Net?
That's not VB.

You can use:

While ...
...
Wend

If you need an Exit statement use:

Do While ...
...
If ... Then Exit Do
Loop

Or:

For i=1 To x
...
If ... Then Exit For
Next

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


Am Tue, 21 Nov 2006 08:19:01 -0800 schrieb Rayo K:

OK,

I changed my code so it uses a While statement, but I keep getting and

error
saying I can't use Exit While or End While. Is "While" different in VBA

than
VB?

Here is my code:

Sub main()

'handles for manipulated objects
Dim app As Outlook.Application
Dim space As NameSpace
Dim box1 As MAPIFolder
Dim box2 As MAPIFolder
Dim folder1 As MAPIFolder
Dim folder2 As MAPIFolder
Dim itemcoll1 As Items
Dim itemcoll2 As Items
Dim item1 As MailItem
Dim item2 As MailItem

Dim x As Integer, y As Integer
Dim numItems As Integer
Dim FCont As Boolean
Dim FSame As Boolean



'define the handles
Set app = CreateObject("Outlook.Application")
Set space = MyApp.GetNamespace("MAPI")
Set box1 = MyNameSpace.Folders("Test1")
Set folder1 = box1.Folders("Mail1")
Set box2 = MyNameSpace.Folders("Test2")
Set folder2 = box2.Folders("Mail2")
Set itemcoll1 = folder1.Items
Set itemcoll2 = folder2.Items

'sort items collections by received date
itemcoll1.Sort "[ReceivedTime]", True
itemcoll2.Sort "[ReceivedTime]", True


'step through all items in collection 1
numItems = itemcoll1.Count

For x = 1 To numItems
Set item1 = itemcoll1(x)
y = 1
FCont = True
'go through items in folder 2
While FCont
'If there is no item corresponding to y, then the email is not in the
folder.
If y itmecoll2.Count Then
item1.Copy.Move folder2
exit while
End If

Set item2 = itemcoll2(y)
'If the received time is earlier than the item in folder 2, go to the
next one. _
Otherwise check if they are the same

If item1.ReceivedTime = item2.ReceivedTime Then
FCont = False

'Check if emails are the same by received time, subject, and

sender

FSame = True
If Not (item1.Subject = item2.Subject) Then FSame = False
End If
If Not (item1.ReceivedTime = item2.ReceivedTime) Then FSame =

False
End If
If Not (item1.SenderEmailAddress = item2.SenderEmailAddress) Then
FSame = False
End If
'If any of these were not the same, the items are different
If FSame = False Then
item1.Copy.Move folder2
End If
End If
'if the item2 was earlier find one that is later.
y = y + 1
End While

Next x

End Sub





"Michael Bauer [MVP - Outlook]" wrote:



Outlook doesn't provide you with such a routine, you have to write it
yourself.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Am Mon, 20 Nov 2006 14:53:02 -0800 schrieb Rayo K:

Hello,

I am trying to write a macro that will inspect a certain folder, and if

it
contains an email that is not already in the "Saved" folder, copy that

email.

Right now I am having trouble identifiying an email as a duplicate item.

Is
there a routine taht will quickly identify two Mailitems as being the

same?
Right now I am comparing receivedtime, subject, and sender properties

one
at
a time.

Thanks


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Duplicate Email Messages Hasan Sheriff Outlook - General Queries 2 October 5th 06 10:51 AM
Duplicate Email from Inbox Kudos Outlook - Calandaring 1 August 30th 06 04:52 PM
Duplicate Email Wisley Outlook - General Queries 2 June 5th 06 02:55 PM
My outlook just pops up and checks mail. How do I stop this? MHR Outlook - Installation 1 May 3rd 06 04:22 PM
email forwarding macro JTL Outlook and VBA 2 February 7th 06 05:42 PM


All times are GMT +1. The time now is 10:57 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.