![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#4
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
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 |