Trying to delete appointment from other person's outlook calendar VBA

nortonm

Registered User.
Local time
Today, 06:37
Joined
Feb 11, 2016
Messages
49
Hi,
I have code that creates appointments in 3 tech colleagues calendars, and I need code to also remove those appointments when the particular class is cancelled.

The code for adding them to the new appointment is as below:

If vbYes = MsgBox("Send Calendar Appointments?", vbYesNo) Then

Dim outMail As Outlook.AppointmentItem
Set outMail = Outlook.CreateItem(olAppointmentItem)
outMail.Subject = "Lab Booking - " & FullName & " - for date " & Forms!frmLabSession_edit!BookingDate
outMail.Mileage = Me.LabBooking_ID
outMail.Location = Forms!frmLabSession_edit!frm_qryLabsBookedPerBooking_subform!RoomNo
outMail.MeetingStatus = olMeeting
outMail.Start = BookingDate & " " & TimeFrom
outMail.End = BookingDate & " " & TimeTo
outMail.ReminderMinutesBeforeStart = 21600
outMail.RequiredAttendees = "Person1@tees.ac.uk; Person2@tees.ac.uk; Person3@tees.ac.uk" & Me.txtCCList
outMail.Body = "You have received this notification with a 15 days countdown to cover periods of leave when you may not have received initial notification." & Chr$(13) & _
Chr$(13) & Me.Notes
outMail.Attachments.Add FileName
outMail.Send
Set outMail = Nothing
End If


I have code that works for deleting appointments based on the subject line, but I can't figure out how to add recipients - the other calendar users - it only removes it from my calendar at the moment. This is the code that works to remove from my calendar:

Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objAppointment As Outlook.AppointmentItem
Dim lngDeletedAppointements As Long
Dim strSubject As String
Dim strLocation As String
Dim dteStartDate As Date

'******************************** Set Criteria for DELETION here ********************************
strSubject = "Lab Booking - " & FullName & " - for date " & Forms!frmLabSession_edit!BookingDate
strLocation = Forms!frmLabSession_edit!frm_qryLabsBookedPerBooking_subform!RoomNo
dteStartDate = BookingDate
'************************************************************************************************

Set objOutlook = Outlook.Application
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)

For Each objAppointment In objFolder.Items
If objAppointment.Subject = strSubject And objAppointment.Location = strLocation And _
objAppointment.Start > dteStartDate Then
objAppointment.Delete
lngDeletedAppointements = lngDeletedAppointements + 1
End If
Next

MsgBox lngDeletedAppointements & " appointment(s) DELETED.", vbInformation, "DETETE Appointments"


I'm not sure how to declare or state in the code the attendees to remove the item from, as the top code does to send them to in the first place. Does anybody know how I would go about it?

Many Thanks
 
The issue is permissions, perhaps. You can SEND a task or appointment but once it is in someone else's calendar (and they have accepted it) then it is theirs, not yours. They need to grant you delete permission (I think).

This is typically done manually in Outlook (since granting this kind of permission is a one-time action). It has been a while since I did this, but it should be easy enough to Google it: Grant Outlook DELETE permission to other user. The search for that string turned up several requests. Here is one that came back. There were more but I didn't want to overload you.

 
Ah, right. Thanks, i'll have a look through. I think I have edit to their calendars, but that doesn't include delete, that would have to be full control I guess.
 
is it possible to edit?
firewall/antivirus don't detect such intrusion?
 
Yes, Thanks, that would also be useful; although a number of sessions are deleted, an equal or higher number are updated. I'll have to find some code for updating the main information fields instead of deleting the appointment itself.
 
Hi - re 'The Doc Man' reply: I have confirmed that I have delete rights, I can view their calendar entry and delete the appointment from their calendar from my Outlook. With this in mind, and confirming the above code does work in deleting from my calendar, do you know if it's possible to put somewhere in the statement whose calendar/s it should also be deleted from? (In the same way you can nominate attendees in outMail.RequiredAttendees section?) Thanks for looking, I'm still looking and trying things out myself.
 
Actually, for reference, I got the answer. I need to put the following code in:

Code:
objAppointment.MeetingStatus = olMeetingCanceled
objAppointment.Save
objAppointment.Send
objAppointment.Delete

so that deletes from mine, and creates cancellation in other attendees calendars. Thanks all.
 
Hi - apologies if I should have re-posted this as a new query, but I've just realised after coming back after covid that the cancellation works fine - except - that if someone cancels an appointment from the database that someone else entered as an appointment, then all appointments are cancelled except for the person's that created the appointment in the first place. Hope that makes sense. Any ideas how that can be overruled in the code? All outlook permissions are set for this, in fact I gave my colleagues 'owner' level permissions with complete delete control over my calendar.
 

Users who are viewing this thread

Back
Top Bottom