We have seen how to send and received emails from/to Excel via Outlook using VBA macros. In this post we see how to send meet invites from Excel targeting an appointment item instead of mail item. The appointment becomes a meeting invite in the recipient’s calendar in Outlook.
Macro code:
Dim OutApp As New Outlook.Application 'early binding
Dim OutInvite As AppointmentItem
With OutInvite
.MeetingStatus = olMeeting
.RequiredAttendees = "excelmacromania@outlook.com; xlsgsdata@gmail.com"
.Subject = "test meet invite"
.Body = "This is a test meet invite"
.Start = "05/12/2023 10:00"
.Location = "Your Office"
.Duration = 30
.Display
'.Send
End With
Set OutInvite = Nothing
Set OutApp = Nothing
End Sub
Macro explained:
- First we declare two object variables to assign the Outlook application and Outlook items (appointment). Object variables are a special type of variable used to store VBA objects, ActiveX objects, and other types of objects.
- Then we use the CreateObject function to initialize Outlook, and we assign the Outlook Application object to the variable OutApp. Now we can use the CreateItem method of the Outlook Application object to assign the an appointment item to the variable OutInvite.
- Using a With statement, we set properties of the appointment item (OutInvite) for meeting status, required attendees, meet invite subject, body, start time, duration, and location. The display method shows the meet invite in Outlook before sending. If we want to fully automate it, we have to use the Send method too (and no need for Display).
- Finally, we clear the object variables or set both to nothing – this is good practice when coding VBA.
IMPORTANT: If you do not have Outlook installed
and setup in your machine, the macro will not work.
This is how we send meet invites from Excel using
VBA macros.
Other examples:
- How to put Range Data Into Array with Excel VBA macros
- How to Add Sheets From Selection with Excel VBA macros
- How to Add Multiple Series To Chart with Excel VBA macros
No comments:
Post a Comment