![]() |
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 |
#1
|
|||
|
|||
![]()
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 |
Ads |
#2
|
|||
|
|||
![]()
1 0 is always going to fail (i.e. return FALSE).
Aravind "ryguy7272" wrote: 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 |
#3
|
|||
|
|||
![]()
Good catch Aravind. Actually, I had no tasks in the Task Folder at the time.
Now with a few tasks in there, and two dupes, it seems to be counting the items correctly, the only thing it does not do is delete the duplicate tasks when the dupes are found and counted. I've narrowed the problem to this snippet of code: newTask.Mileage = "DELETEME" iCounter = iCounter + 1 newTask.Save End If Set oldTask = newTask I think the one line that is giving me problems is this: Set oldTask = newTask I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). What is the code to remove the entire Task from the Task folder? I'm sooooo close to resolving this; at this point I just need a little push. Regards, Ryan-- -- RyGuy "Aravind" wrote: 1 0 is always going to fail (i.e. return FALSE). Aravind "ryguy7272" wrote: 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 |
#4
|
|||
|
|||
![]()
I haven't worked with Tasks yet, but isn't there a newtask.Delete?
Aravind "ryguy7272" wrote: Good catch Aravind. Actually, I had no tasks in the Task Folder at the time. Now with a few tasks in there, and two dupes, it seems to be counting the items correctly, the only thing it does not do is delete the duplicate tasks when the dupes are found and counted. I've narrowed the problem to this snippet of code: newTask.Mileage = "DELETEME" iCounter = iCounter + 1 newTask.Save End If Set oldTask = newTask I think the one line that is giving me problems is this: Set oldTask = newTask I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). What is the code to remove the entire Task from the Task folder? I'm sooooo close to resolving this; at this point I just need a little push. Regards, Ryan-- -- RyGuy "Aravind" wrote: 1 0 is always going to fail (i.e. return FALSE). Aravind "ryguy7272" wrote: 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 |
#5
|
|||
|
|||
![]()
No...well it's not that easy. I tried several combinations of things, and
this causes an error on this line: If ((newTask.Subject = oldTask.Subject)) Then Any other ideas? TIA! -- RyGuy "Aravind" wrote: I haven't worked with Tasks yet, but isn't there a newtask.Delete? Aravind "ryguy7272" wrote: Good catch Aravind. Actually, I had no tasks in the Task Folder at the time. Now with a few tasks in there, and two dupes, it seems to be counting the items correctly, the only thing it does not do is delete the duplicate tasks when the dupes are found and counted. I've narrowed the problem to this snippet of code: newTask.Mileage = "DELETEME" iCounter = iCounter + 1 newTask.Save End If Set oldTask = newTask I think the one line that is giving me problems is this: Set oldTask = newTask I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). What is the code to remove the entire Task from the Task folder? I'm sooooo close to resolving this; at this point I just need a little push. Regards, Ryan-- -- RyGuy "Aravind" wrote: 1 0 is always going to fail (i.e. return FALSE). Aravind "ryguy7272" wrote: 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 |
#6
|
|||
|
|||
![]()
What is the error?
Aravind "ryguy7272" wrote: No...well it's not that easy. I tried several combinations of things, and this causes an error on this line: If ((newTask.Subject = oldTask.Subject)) Then Any other ideas? TIA! -- RyGuy "Aravind" wrote: I haven't worked with Tasks yet, but isn't there a newtask.Delete? Aravind "ryguy7272" wrote: Good catch Aravind. Actually, I had no tasks in the Task Folder at the time. Now with a few tasks in there, and two dupes, it seems to be counting the items correctly, the only thing it does not do is delete the duplicate tasks when the dupes are found and counted. I've narrowed the problem to this snippet of code: newTask.Mileage = "DELETEME" iCounter = iCounter + 1 newTask.Save End If Set oldTask = newTask I think the one line that is giving me problems is this: Set oldTask = newTask I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). What is the code to remove the entire Task from the Task folder? I'm sooooo close to resolving this; at this point I just need a little push. Regards, Ryan-- -- RyGuy "Aravind" wrote: 1 0 is always going to fail (i.e. return FALSE). Aravind "ryguy7272" wrote: 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 |
#7
|
|||
|
|||
![]()
If you have a valid reference to an item, say a Task, then item.Delete
works. So does the Remove method of the Items collection, using an index reference for Remove. In that error are both oldTask and newTask instantiated (not Nothing or null)? If one or both are null then trying to access .Subject would fail. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "ryguy7272" wrote in message ... No...well it's not that easy. I tried several combinations of things, and this causes an error on this line: If ((newTask.Subject = oldTask.Subject)) Then Any other ideas? TIA! -- RyGuy |
#8
|
|||
|
|||
![]()
The only reason this blanks the subject is that Remove is an undeclared variable and so is treated as a null string. Add an Option Explicit statement to the declarations section of your code module to avoid being similarly misled in the future.
As Aravind said newTask.Delete would is the correct method to call to delete the item. And if you're just going to delete it, what's the point of changing the Mileage or Subject property? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "ryguy7272" wrote in message ... I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). |
#9
|
|||
|
|||
![]()
If I use this:
newtask.Delete I get an error on this line: If ((newTask.Subject = oldTask.Subject)) Then ....not found? Make any sense? -- RyGuy "Aravind" wrote: What is the error? Aravind "ryguy7272" wrote: No...well it's not that easy. I tried several combinations of things, and this causes an error on this line: If ((newTask.Subject = oldTask.Subject)) Then Any other ideas? TIA! -- RyGuy "Aravind" wrote: I haven't worked with Tasks yet, but isn't there a newtask.Delete? Aravind "ryguy7272" wrote: Good catch Aravind. Actually, I had no tasks in the Task Folder at the time. Now with a few tasks in there, and two dupes, it seems to be counting the items correctly, the only thing it does not do is delete the duplicate tasks when the dupes are found and counted. I've narrowed the problem to this snippet of code: newTask.Mileage = "DELETEME" iCounter = iCounter + 1 newTask.Save End If Set oldTask = newTask I think the one line that is giving me problems is this: Set oldTask = newTask I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). What is the code to remove the entire Task from the Task folder? I'm sooooo close to resolving this; at this point I just need a little push. Regards, Ryan-- -- RyGuy "Aravind" wrote: 1 0 is always going to fail (i.e. return FALSE). Aravind "ryguy7272" wrote: 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 |
#10
|
|||
|
|||
![]()
If you delete the item, it's not going to around any more to have its subject changed. Why would you want to change the subject of a deleted item anyway?
-- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "ryguy7272" wrote in message ... If I use this: newtask.Delete I get an error on this line: If ((newTask.Subject = oldTask.Subject)) Then ...not found? Make any sense? -- RyGuy "Aravind" wrote: What is the error? Aravind "ryguy7272" wrote: No...well it's not that easy. I tried several combinations of things, and this causes an error on this line: If ((newTask.Subject = oldTask.Subject)) Then Any other ideas? TIA! -- RyGuy "Aravind" wrote: I haven't worked with Tasks yet, but isn't there a newtask.Delete? Aravind "ryguy7272" wrote: Good catch Aravind. Actually, I had no tasks in the Task Folder at the time. Now with a few tasks in there, and two dupes, it seems to be counting the items correctly, the only thing it does not do is delete the duplicate tasks when the dupes are found and counted. I've narrowed the problem to this snippet of code: newTask.Mileage = "DELETEME" iCounter = iCounter + 1 newTask.Save End If Set oldTask = newTask I think the one line that is giving me problems is this: Set oldTask = newTask I tried things like this: newTask.Subject = Remove This removes the Subject from the Task (appropriate, right). What is the code to remove the entire Task from the Task folder? I'm sooooo close to resolving this; at this point I just need a little push. Regards, Ryan-- -- RyGuy "Aravind" wrote: 1 0 is always going to fail (i.e. return FALSE). Aravind "ryguy7272" wrote: 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
I need an expert! | Terri | Outlook - General Queries | 3 | August 23rd 07 07:12 PM |
Expert to convert a Lotus Notes 6 .nsf to Outlook .pst file | [email protected] | Outlook - General Queries | 0 | June 28th 07 08:47 AM |
Creating Top Level Folder within Outlook 2003 | Adrian Butler | Outlook and VBA | 1 | April 24th 07 03:15 PM |
Wanted: Outlook Expert for Personal Assistance | [email protected] | Outlook - General Queries | 3 | September 11th 06 04:14 AM |
I just tried and I want to contact an expert. | Jerzy | Outlook - General Queries | 1 | March 27th 06 01:07 AM |