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

Need Help from an Outlook Expert; Probably MVP-Level



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old February 1st 08, 03:42 PM posted to microsoft.public.outlook.program_vba
ryguy7272
external usenet poster
 
Posts: 26
Default Need Help from an Outlook Expert; Probably MVP-Level

The code below fails on this line:
While ((j totalcount) And (myItems(j).Class olTask))

I put the cursor over j and see that Excel interprets it as 1, and I put the
cursor over totalcount and I see that Excel interprets it as 0; both of these
values seem correct to me.


Public Sub DeleteDuplicateTasks()

Dim oldTask As TaskItem, newTask As TaskItem, j As Integer
Dim iCounter As Integer

Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
'myItems.Sort "[File As]", olDescending
totalcount = myItems.Count
j = 1
While ((j totalcount) And (myItems(j).Class olTask))
j = j + 1
Wend
Set oldTask = myItems(j)
For i = j + 1 To totalcount
If (myItems(i).Class = olTask) Then
'(newTask.Body = oldTask.Body) And _

Set newTask = myItems(i)
If ((newTask.Subject = oldTask.Subject)) Then
' (newTask.DueDate = oldTask.DueDate) And _

newTask.Mileage = "DELETEME"
iCounter = iCounter + 1
newTask.Save
End If
Set oldTask = newTask
End If
Next i
If iCounter = 0 Then
MsgBox "No duplicate Tasks were detected in " & totalcount & " Tasks!",
vbInformation, "No duplicates"
Else
MsgBox iCounter & " duplicate Tasks were detected and flagged!",
vbInformation, "Duplicates detected"
End If
End Sub

I found this code he
http://www.outlookcode.com/threads.a...essageid=21714
I commented out this line:
'myItems.Sort "[File As]", olDescending

I had it running a couple of days ago, but now it doesn’t run at all.
Although the results were somewhat incorrect, at least the code ran. I tried
to make a few small modifications, and now it doesn’t do anything at all.


Ken gave me the code below (thanks buddy).
The code below fails on this line:
Set colRestrict = myItems.Restrict("[Subject] = " & Chr(34) &
newTask.Subject & Chr(34))

…I made a small modification to Ken’s code and I’m ignoring any possibility
of word wrap as the culprit.

Sub DeleteDupes()
Set myNameSpace = GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myItems = myFolder.Items
Dim colRestrict As Outlook.Items
Set colRestrict = myItems.Restrict("[Subject] = " & Chr(34) &
newTask.Subject & Chr(34))
If colRestrict.Count = 0 Then ' no items with that Subject
'blah, blah, whatever
Else ' there is at least one dupe
' find the dupe and delete it
If colRestrict.Count = 1 Then
colRestrict.Items(1).Delete
Else
For i = colRestrict.Count To 1 Step -1
colRestrict.Items(i).Remove
Next
End If
End If
End Sub


Basically, I am trying to eliminate any and all duplicate Tasks in the Task
folder. I have some great experience doing VBA programming in an Excel
environment but virtually no experience doing VBA programming in an Outlook
environment, so I am at a huge disadvantage here. Can any Outlook expert
review these two Subs and find anything wrong here? I can’t figure out what
the problem is.

Regards,
Ryan--



--
RyGuy
 




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
I need an expert! Terri Outlook - General Queries 3 August 23rd 07 06:12 PM
Expert to convert a Lotus Notes 6 .nsf to Outlook .pst file [email protected] Outlook - General Queries 0 June 28th 07 07:47 AM
Creating Top Level Folder within Outlook 2003 Adrian Butler Outlook and VBA 1 April 24th 07 02:15 PM
Wanted: Outlook Expert for Personal Assistance [email protected] Outlook - General Queries 3 September 11th 06 03:14 AM
I just tried and I want to contact an expert. Jerzy Outlook - General Queries 1 March 27th 06 12:07 AM


All times are GMT +1. The time now is 04:38 AM.


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.