![]() |
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
|
|||
|
|||
![]()
Hi i write this:
Sub CleanUp() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim colCal As Outlook.Items Dim objAppt As Outlook.AppointmentItem Dim objTsk As Outlook.TaskItem Set objOL = CreateObject("Outlook.Application") Set objNS = objOL.GetNamespace("MAPI") Set colCal = objNS.GetDefaultFolder(olFolderCalendar).Items On Error Resume Next For Each objAppt In colCal If objAppt.Categories = "Work" And DateDiff("d", objAppt.Start, Now()) 0 Then objAppt.Delete End If Next Set objAppt = Nothing Set objTsk = Nothing Set colCal = Nothing End Sub the problem is if objAppt it's a recurring object the metod Delete remove all, instead i want to remove only a individual occurrence. TNX |
#2
|
|||
|
|||
![]()
Two things first.
If this is Outlook VBA code then don't create an Outlook.Application object, use the intrinsic Application object exposed in the Outlook VBA. Second, when deleting items from a collection never use a For Each loop. By reducing the size of the collection the internal loop counter is being messed with, which usually results in deleting only half the items. Use a count down For loop instead: Dim i As Long Dim Count As Long Count = colCal.Count For i = Count To 1 Step -1 'etc. Next To remove an individual occurrence of a recurring series you must first test that the item is recurring, get the master appointment, then the recurrence pattern and traverse the pattern to find the occurrence you want: If objAppt.IsRecurring Then Dim oRecur As Outlook.RecurrencePattern Set oRecur = objAppt.GetRecurrencePattern() From here you have to use the RecurrencePattern.GetOccurrence(startDate) method to retrieve individual recurrence items. Once you have an individual occurrence you can just delete it as usual. You can use the other properties of the recurrence pattern to traverse the entire series if you want, using the decoded pattern and GetOccurrence() to reach each item. If you don't get an item for a specified period you then go to the Exceptions collection of the pattern and check each item there for an Exception object that has the OriginalDate that matches the date you want. Every recurring item in the series that has been modified or deleted lives in the Exceptions collection. There are examples of working with a recurrence pattern in the code snippets in the Object Browser Help for each recurrence pattern property. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Skipper" wrote in message ... Hi i write this: Sub CleanUp() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim colCal As Outlook.Items Dim objAppt As Outlook.AppointmentItem Dim objTsk As Outlook.TaskItem Set objOL = CreateObject("Outlook.Application") Set objNS = objOL.GetNamespace("MAPI") Set colCal = objNS.GetDefaultFolder(olFolderCalendar).Items On Error Resume Next For Each objAppt In colCal If objAppt.Categories = "Work" And DateDiff("d", objAppt.Start, Now()) 0 Then objAppt.Delete End If Next Set objAppt = Nothing Set objTsk = Nothing Set colCal = Nothing End Sub the problem is if objAppt it's a recurring object the metod Delete remove all, instead i want to remove only a individual occurrence. TNX |
#3
|
|||
|
|||
![]() "Ken Slovak - [MVP - Outlook]" wrote: Two things first. If this is Outlook VBA code then don't create an Outlook.Application object, use the intrinsic Application object exposed in the Outlook VBA. tnx, how? Second, when deleting items from a collection never use a For Each loop. By reducing the size of the collection the internal loop counter is being messed with, which usually results in deleting only half the items. Use a count down For loop instead: Dim i As Long Dim Count As Long Count = colCal.Count For i = Count To 1 Step -1 'etc. Next there isn't only recurring appointment, do you conferme whatever your tip? To remove an individual occurrence of a recurring series you must first test that the item is recurring, get the master appointment, then the recurrence pattern and traverse the pattern to find the occurrence you want: If objAppt.IsRecurring Then Dim oRecur As Outlook.RecurrencePattern Set oRecur = objAppt.GetRecurrencePattern() From here you have to use the RecurrencePattern.GetOccurrence(startDate) method to retrieve individual recurrence items. Once you have an individual occurrence you can just delete it as usual. You can use the other properties of the recurrence pattern to traverse the entire series if you want, using the decoded pattern and GetOccurrence() to reach each item. If you don't get an item for a specified period you then go to the Exceptions collection of the pattern and check each item there for an Exception object that has the OriginalDate that matches the date you want. Every recurring item in the series that has been modified or deleted lives in the Exceptions collection. There are examples of working with a recurrence pattern in the code snippets in the Object Browser Help for each recurrence pattern property. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Skipper" wrote in message ... Hi i write this: Sub CleanUp() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim colCal As Outlook.Items Dim objAppt As Outlook.AppointmentItem Dim objTsk As Outlook.TaskItem Set objOL = CreateObject("Outlook.Application") Set objNS = objOL.GetNamespace("MAPI") Set colCal = objNS.GetDefaultFolder(olFolderCalendar).Items On Error Resume Next For Each objAppt In colCal If objAppt.Categories = "Work" And DateDiff("d", objAppt.Start, Now()) 0 Then objAppt.Delete End If Next Set objAppt = Nothing Set objTsk = Nothing Set colCal = Nothing End Sub the problem is if objAppt it's a recurring object the metod Delete remove all, instead i want to remove only a individual occurrence. TNX |
#4
|
|||
|
|||
![]()
How to use the intrinsic Application object? Just substitute it for any
Outlook.Application object you are creating. Wherever you are now using objOL just use Application instead. No need to use CreateObject or New on it. Whenever you remove any objects from a collection use a down counting loop. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Skipper" wrote in message ... "Ken Slovak - [MVP - Outlook]" wrote: Two things first. If this is Outlook VBA code then don't create an Outlook.Application object, use the intrinsic Application object exposed in the Outlook VBA. tnx, how? Second, when deleting items from a collection never use a For Each loop. By reducing the size of the collection the internal loop counter is being messed with, which usually results in deleting only half the items. Use a count down For loop instead: Dim i As Long Dim Count As Long Count = colCal.Count For i = Count To 1 Step -1 'etc. Next there isn't only recurring appointment, do you conferme whatever your tip? snip |
#5
|
|||
|
|||
![]() "Ken Slovak - [MVP - Outlook]" wrote: How to use the intrinsic Application object? Just substitute it for any Outlook.Application object you are creating. Wherever you are now using objOL just use Application instead. No need to use CreateObject or New on it. if i use GetObject fuction ? |
#6
|
|||
|
|||
![]()
Just use Application, no CreateObject or New or GetObject.
-- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Skipper" wrote in message ... "Ken Slovak - [MVP - Outlook]" wrote: How to use the intrinsic Application object? Just substitute it for any Outlook.Application object you are creating. Wherever you are now using objOL just use Application instead. No need to use CreateObject or New on it. if i use GetObject fuction ? |
#7
|
|||
|
|||
![]()
WORKS!!!
here how to remove past occurrence: Dim colCal As Outlook.Items Set colCal = Outlook.Application.GetNamespace("MAPI").GetDefaul tFolder(olFolderCalendar).Items Dim i, j As Integer Dim objAppt As Outlook.AppointmentItem Dim myRecur As Outlook.RecurrencePattern Dim objRecur As Outlook.AppointmentItem On Error Resume Next For i = colCal.count To 1 Step -1 Set objAppt = colCal.Item(i) If objAppt.IsRecurring Then Set myRecur = objAppt.GetRecurrencePattern For j = 0 To myRecur.Occurrences - 1 Set objRecur = myRecur.GetOccurrence(objAppt.Start + j * 7) If DateDiff("s", objRecur.End, Now()) 0 Then MsgBox "Deleted " & objRecur.Subject & " " & objRecur.Start objRecur.Delete End If Next End If Next |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cannot reschedule an occurrence of the recurring appointment | Tim | Outlook - Calandaring | 4 | August 12th 06 08:55 AM |
Sort by Next Occurrence of Recurring Appointment for Birthdays | Josetta | Outlook - General Queries | 0 | June 1st 06 12:06 AM |
outlook today recurring occurrence | AJ Meelan | Outlook - Calandaring | 3 | January 31st 06 04:08 PM |
How can I get a listing of each occurrence of a recurring event? | Bethany | Outlook - Calandaring | 1 | January 25th 06 01:39 PM |
Can I skip one occurrence of a recurring APPOINTMENT? | Sam | Outlook - Calandaring | 2 | January 23rd 06 02:40 PM |