![]() |
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 |
Ads |
#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
|
|||
|
|||
![]() "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 |
#8
|
|||
|
|||
![]()
"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 |
#9
|
|||
|
|||
![]()
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 |
#10
|
|||
|
|||
![]()
"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 |
|
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 |