Delete all appointments from Outlook Calendar

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hey Guys,
One of the big guys in our company decided we need new software... guess what?
No short list, no use cases, no selection criteria, no nothing!
So what happens when you start using it? Surpise-Surpise, IT DOESNT FIT YOUR NEEDS! :o)
Anyways, that was just my frustration speaking, here it goes:
Ive got an HTML file that has a table in it. The table is some kind of a planboard. It contains the amount of planned hours for an employee for a customer on day x over a whole year. Our guys need it in their outlook schedules.
Here is what ive built so far
- Form to set parameters (select starttime, select input html file, alerting on or off)
- Function that deletes all appointments within a set time frame that have a subject that starts with "project: "
- Class that extracts all appointments from html and transforms them into outlook appointments
<img src="http://i978.photobucket.com/albums/ae264/jb_theman/2outlook1.jpg" alt="
Everything works peachy! -Except deleting appointments. Im stuck! Ive tried making a selection of appointments between two dates, ive tried looking for appointments on all days between to dates... and the one below which seems to work to some extend ...
Here is what ive put together....

<pre lang="x-vbnet Private Sub buggyCode()
TotalAdded = 0
TotalDeleted = 0

Dim start As Date = dStart.Value
Dim eind As Date = dEnd.Value
Dim Dag As Date = start

Dim setStartTime As String = cmDayStart.SelectedItem.ToString
Dim StartHour As Integer = 8
Dim StartMinute As Integer = 30

Dim DeleteExisting As Boolean = True

If eind >= start Then
System.Windows.Forms.Application.DoEvents()
Dim objNameSpace As Outlook.NameSpace = objOutlook.GetNamespace("mapi")
Dim calendar As Outlook.MAPIFolder = objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
Dim calendarItems As Outlook.Items = calendar.Items
Dim Appointment As Microsoft.Office.Interop.Outlook.AppointmentItem

Search the Appointments in the Calendar Folder to Delete.
The appointment has be between the startdate and the enddate
If it starts with "Project: " it can be deleted
If DeleteExisting = True Then
For Each itm In objNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar).Items
Try
Appointment = itm
If Appointment.Start >= start And Appointment.End <= eind Then
If Mid(Appointment.Body, 1, 9).ToLower = "project: ".ToLower Then
Appointment.Delete()
TotalDeleted += 1
UpdateStatus("Removed " & TotalDeleted & " Appointments From Calendar")
End If
End If
Catch ex As Exception
probably a meeting request
End Try
Next
End If
End If

End Sub

[/code]

It does not delete all items, just some of them. Of the 23 occurences it should delete, it only deletes 12 OR 13 at random.
Hope you guys can help me out with this one,
Cheers,
John


View the full article
 
Back
Top