![]() |
|
Remove an individual occurrence of recurring appointment
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 |
Remove an individual occurrence of recurring appointment
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 |
Remove an individual occurrence of recurring appointment
"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 |
Remove an individual occurrence of recurring appointment
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 |
Remove an individual occurrence of recurring appointment
"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 ? |
Remove an individual occurrence of recurring appointment
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 ? |
Remove an individual occurrence of recurring appointment
"Ken Slovak - [MVP - Outlook]" wrote: Just use Application, no CreateObject or New or GetObject. sorry, and thanks you for your patient, but i don't understand. can you make a sample? TNX |
Remove an individual occurrence of recurring appointment
"Ken Slovak - [MVP - Outlook]" wrote:
Just use Application, no CreateObject or New or GetObject. ok i use: Set colCal = Outlook.Application.GetNamespace("MAPI").GetDefaul tFolder(olFolderCalendar).Items for the single instance of a recurring appointment i try this: Dim oRecur As Outlook.RecurrencePattern Dim myException As Outlook.Exception For i = count To 1 Step -1 Set objAppt = colCal.Item(i) If objAppt.IsRecurring Then If objAppt.Categories = "Work" And objAppt.Subject = "Economia" Then Set oRecur = objAppt.GetRecurrencePattern() For j = 1 To oRecur.Occurrences Set myException = oRecur.Exceptions.Item(j) ----------------- MsgBox myException.Subject & " " & myException.Start Next End If End If Next but i receive an error on line ------ about "matrix index out of interval" TNX A LOT |
Remove an individual occurrence of recurring appointment
Exceptions is a separate collection, it has nothing to do with Occurrences.
Only if every occurrence in the recurring series were modified or deleted would the 2 counts be equal. To repeat what I said originally: 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 ... "Ken Slovak - [MVP - Outlook]" wrote: Just use Application, no CreateObject or New or GetObject. ok i use: Set colCal = Outlook.Application.GetNamespace("MAPI").GetDefaul tFolder(olFolderCalendar).Items for the single instance of a recurring appointment i try this: Dim oRecur As Outlook.RecurrencePattern Dim myException As Outlook.Exception For i = count To 1 Step -1 Set objAppt = colCal.Item(i) If objAppt.IsRecurring Then If objAppt.Categories = "Work" And objAppt.Subject = "Economia" Then Set oRecur = objAppt.GetRecurrencePattern() For j = 1 To oRecur.Occurrences Set myException = oRecur.Exceptions.Item(j) ----------------- MsgBox myException.Subject & " " & myException.Start Next End If End If Next but i receive an error on line ------ about "matrix index out of interval" TNX A LOT |
Remove an individual occurrence of recurring appointment
"Ken Slovak - [MVP - Outlook]" wrote:
To repeat what I said originally: 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. ok, but i don't understand how getoccurrence works. how i can get all the occurrence one by one, tests if the date it's before today and if true delete it ? why i must specify a startdate ? PLZ can you explain with code, i'm not english native speaker and perhaps i can understand code batter. TNX |
All times are GMT +1. The time now is 10:56 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-2006 OutlookBanter.com