Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA can't send calendar appointment

When I manually make a calendar reminder/appointment, I can then click "Invite Attendees" and chose the people to invite and then click "Send" and everyone will receive that calendar reminder/appointment.

I have the following code to make a reminder programmatically, but it won't send to the intended recipients. If I open the reminder after the script has run and click on "Invite Attendees" I can see the list is filled with the people I want to send the reminder to, so I'm not really sure why it's not actually sending the reminder to them.

Can anyone shed some light on this for me?

Private Function CreateAppointment(SubjectStr As String, BodyStr As String, StartTime As Date, EndTime As Date, AllDay As Boolean)
    Dim olApp As Outlook.Application
    Dim Appt As Outlook.AppointmentItem
    ' Only create the reminder if there's no duplicate
    If (CheckForDuplicates(SubjectStr) = False) Then
        Set olApp = CreateObject("Outlook.Application")
        Set Appt = olApp.CreateItem(olAppointmentItem)
        Appt.Recipients.Add ("John Doe")
        Appt.Recipients.ResolveAll
        Appt.Subject = SubjectStr
        Appt.Start = StartTime
        Appt.End = EndTime
        Appt.AllDayEvent = AllDay
        Appt.Body = BodyStr
        Appt.ReminderSet = True
        Appt.Save
        Appt.Send
    End If
    Set Appt = Nothing
    Set olApp = Nothing
End Function
like image 952
FizzBuzz Avatar asked Sep 30 '11 00:09

FizzBuzz


1 Answers

A meeting is a specific type of appointment -- an appointment that other people are invited to.

In order to make an appointment a meeting, you need to do more than just invite attendees. You need to set the status to 'Meeting'. Add this to your code:

Appt.MeetingStatus = olMeeting

Also note that you set a reminder, but didn't set a reminder time. For example,

Appt.ReminderMinutesBeforeStart = 30

Finally, if this is Outlook VBA, why are you using CreateObject? You should be using the native Application Object to derive all your objects.

i.e. instead of

Set olApp = CreateObject("Outlook.Application")

you would use

Set olApp = Outlook.Application

HTH

like image 54
JimmyPena Avatar answered Nov 18 '22 08:11

JimmyPena