Ok so here's what I want to do. I have a custom form that creates an appointment which I invite others to attend from a shared calendar. I want the form to also send an email that is delayed by 2 days from the start date of the appointment, to the person that is invited (the required attendee) that is set within the form. I have a macro in outlook where I can select the appointment in the calendar and then run the macro and it will send the email. But I want the form to do it all (so my coworkers don't have to go into the calendar and select the appointment then run the macro). Can this be done? I'll include the VBA for the macro below. Thanks!
Code:
Sub mail()
Dim obj As Object
Dim Sel As Outlook.Selection
Dim objAppt As Outlook.AppointmentItem
Dim objOutlook As Object
Dim objOutlookMsg As Object
Set Sel = Application.ActiveExplorer.Selection
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
If Sel.Count Then Set obj = Sel(1)
If TypeOf obj Is Outlook.AppointmentItem Then
Set objAppt = obj
Set objTask1 = Application.CreateItem(olTaskItem)
With objOutlookMsg
.To = objAppt.RequiredAttendees
.Subject = "Business Banking Follow up reminder: " & objAppt.Location
'.Body = "This is the body of message"
.HTMLBody = "Test message! " & "Company: " & objAppt.Location & " " & objAppt.Start
dteThen = objAppt.Start + 2
.DeferredDeliveryTime = dteThen
'.Attachments.Add ("c:\myFileToSend.txt")
.Send
End With
End If
End If
On Error Resume Next
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub