COVID-19: Choose between our familiar (but now socially distanced) classroom training courses and our excellent new live online courses.
Use VBA to create Microsoft Team meetings
Did you know that you can create Microsoft Team meetings using VBA in Outlook? This blog shows you how!

Posted by Sam Lowrie on 26 June 2020

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

VBA Outlook Teams Meeting

Here at Wise Owl we have started to use Microsoft Teams for our online training courses. This means we are producing a lot of emails and meetings for courses and pre-course testing.

Wise Owl Training Outlook VBA Teams Meeting

I can't be the only one who is sick of having to click this darn button manually?

There must be a way of automating this process, rather than having to copy and paste all of the details in for each client. When I searched for help online however I hit a brick wall - Teams can't be referenced in VBA.

Here's the sort of information that we have for a course booking - how to turn this into a Teams meeting programmatically?

Wise Owl Training Outlook VBA Teams Meeting

Typical email generated by our system with the information that I need to put into teams.

What I did notice was when you create an Outlook meeting there is the option (if Teams is installed) to add a Teams meeting:

Wise Owl Training Outlook VBA Teams Meeting

With this button I won't need to reference Teams with my VBA; instead I can stick to Outlook!

The solution

Create the meeting in Outlook using the VBA following code, populating the fields you need in the meeting (there's a full list of the methods and properties for a meeting here):

Sub new_teams_meeting

'Create place to store meeting

Dim newmeeting As Outlook.AppointmentItem

Dim meetingparticipants As Outlook.Recipient

'Creates a new calendar appointment

Set newmeeting = Application.CreateItem(olAppointmentItem)

'Change from calendar to meeting

newmeeting.MeetingStatus = olMeeting

'Set the email subject as value in class

newmeeting.Subject = "Subject"

'Set start date/time

newmeeting.Start = #Start date and time#

'Set end date/time

newmeeting.End #End date and time#

'Add target email

Set meetingparticipants = ListOfEmails

'Set meeting as required attendance or optional

meetingparticipants.Type = olRequired

newmeeting.Body = "Set the body of the email"

'Show the meeting

newmeeting.Display

All this is fairly standard, but now comes the part I couldn't figure out: how to add the Teams meeting and a signature. The Sendkeys command tells Outlook to act as if you had pushed those buttons on the keyboard:

'Switch on tab keyboard short cuts

SendKeys "{F10}", True

'Switch to ribbon shortcuts

SendKeys "H", True

'Hit the Microsoft teams meetings button, requires teams to be installed

SendKeys "TM", True

'Now to add signature: Switch to meeting location button

SendKeys "{Tab}", True

'Switch to email body

SendKeys "{Tab}", True

'Highlight all the text

SendKeys "^+{END}", True

'Go to end of text so that the signature is at the bottom

SendKeys "{END}", True

'turn on tab shortcuts

SendKeys "{F10}", True

'select the Insert tab

SendKeys "N", True

'Open the signature drop down

SendKeys "AS", True

'Select first signature and close signature list

SendKeys "{ENTER}"

End Sub

One of the nice things about this is while a link to the meeting is generated, if you cancel the meeting won't be saved!

Wise Owl Training Outlook VBA Teams Meeting

An example of what you might get from us when joining an online course (well, maybe with a few more details on it).

Thanks for reading and I hope this saves you some of the time it cost me!

This blog has 0 threads Add post