Add Microsoft Teams to Outlook Meeting Request - vba

I have code that creates an outlook meeting request and it is working great. I want to be able to make this meeting request a Microsoft Teams Meeting. I cannot find any notes online on the objects to use for this and cannot find any objects in Outlook VBA that look like they will work. Does anyone know how to programmatically add Microsoft Teams to a meeting request?

The easiest way to run the command on the ribbon programmatically. You just need to know the idMso value of the built-in command. The ExecuteMso method of the CoommandBars class is useful in cases where there is no object model for a particular command. Works on controls that are built-in buttons, toggleButtons, and splitButtons. On failure, it returns E_InvalidArg for an invalid idMso, and E_Fail for controls that are not enabled or not visible.
But we deal with an add-in, so their idMso values are not disclosed. In that case your option is to use Accessibility API, see Microsoft Active Accessibility for more information. Microsoft Active Accessibility is a Component Object Model (COM)-based technology that improves the way accessibility aids work with applications running on Microsoft Windows. It provides dynamic-link libraries that are incorporated into the operating system as well as a COM interface and API elements that provide reliable methods for exposing information about UI elements.
As the last resort, you may consider using Windows API function to click the button programmatically.
P.S. You may find the Are the command codes for ExecuteMso documented? page helpful.

You can use this code
Sub teammetting()
Dim nm As Outlook.AppointmentItem
Set nm = Application.CreateItem(olAppointmentItem)
nm.MeetingStatus = olMeeting
nm.Subject = "Subject"
nm.Start = 'format:DD/MM/YYYY HH:MM:SS AM/PM
nm.End =""'format:DD/MM/YYYY HH:MM:SS AM/PM
nm.requiredattendees "mail address of the invitees"
nm.Body = "Set the body of the email"
'Show the meeting
nm.Display
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
end sub
'use this code and try as there isn't any note of objects or

Related

Automatically Closing Outlook Windows via Script/Macro

I'm hoping someone on here can point me in the right direction with some expertise. I have a situation with a client's outlook where we need to close any open draft windows after a new message/draft is opened. Ideally after the 4th new window has opened.
Any "new message" window that opens after this we need the script to close 1st window that opened. Either killing the process, or something similar.
Recently have been looking into Outlook macros, but am unsure if they will help in this instance. (Maybe they are?). Being more familiar with Powershell, figured we could start there.
Looking to get help writing a powershell script, macro, etc to do this on the backend.
The Outlook object model provides all the required events, methods and properties for that. So, VBA macros is the right choice if you don't need to distribute the solution on multiple machines. Otherwise, you need to consider developing a COM add-in instead (for example, a VSTO based one should work for you). See Walkthrough: Create your first VSTO Add-in for Outlook for more information.
You can handle the NewInspector event which is fired whenever a new inspector window is opened, either as a result of user action or through program code. The event occurs after the new Inspector object is created but before the inspector window appears.
You can also check the number of opened inspector windows in Outlook by using the Inspectors.Count property which returns a long indicating the count of objects in the specified collection.
Finally, the Inspector.Close method closes the Inspector and optionally saves changes to the displayed Outlook item. For example, a VBA sample which closes the active inspector instance:
Sub CloseItem()
Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Set myinspector = Application.ActiveInspector
Set myItem = myinspector.CurrentItem
myItem.Close olSave
End Sub

Call Word Menu-Button in VBA?

everyone,
I am new to VBA and would like to know if it is possible to execute a menu button from a WordAddIn.
In the picture you can see which button I would like to execute using VBA.
Unfortunately, I can't record it via macro.
The Word object model allows executing built-in ribbon controls using the CommandBars.ExecuteMso method which executes the control identified by the idMso parameter. This method is useful in cases where there is no object model for a particular command. Works on controls that are built-in buttons, toggleButtons, and splitButtons.
But in your case the control comes from a third-party add-in which doesn't expose IDs and the CommandBars.ExecuteMso method can't find it and invoke the command programmatically.
To get the job done you may consider using the Microsoft Active Accessibility which is a Component Object Model (COM)-based technology that improves the way accessibility aids work with applications running on Microsoft Windows. It provides dynamic-link libraries that are incorporated into the operating system as well as a COM interface and API elements that provide reliable methods for exposing information about UI elements.
Also you may contact the add-in vendor for providing public methods that can be called from your solution. That's also a possible workaround instead of calling UI elements on the ribbon.

How to manage application options/advanced options?

I need to quickly toggle File > Options > Advanced > Reminders > Play reminder sound setting.
In certain meetings I need to keep Outlook running to get reminders, but don't want the reminder sound.
Currently, I manually toggle the File > Options > Advanced > Reminders > Play reminder sound checkmark.
This needs to be an effective single-click.
I don't want to restart Outlook as there are usually many things open.
I cannot add it to the Quick Access Toolbar.
On the left the option is present in the list of QAT commands, but not in the list of Ribbon commands, otherwise we could access it with ExecuteMso.
Three reasons:
The button is disabled when not in the Calendar window. That's just inelegant.
When I click the button, Outlook crashes and I lose everything that wasn't saved. (Autosave isn't sufficient or functioning. That's a different problem.)
Understanding how to access Outlook settings with VBA opens a whole new world of possibilities.
This Microsoft article series starting at https://learn.microsoft.com/en-us/office/vba/outlook/concepts/getting-started/automating-outlook-from-a-visual-basic-application is about automating Outlook user tasks, like making a calendar appointment. That's not what I want, I want to manage Outlook's options.
There are some discussions about COM add-ins as one method, but that appears beyond me. The effort to learn COM add-ins is out of line with manual effort to achieve the desired goal.
I have some limited Outlook VBA experience but am reasonably comfortable with VBA in Word, Excel.
To disable reminder sound you need to set the below registry key to 0.
Registry key: PlaySound (REG_DWORD) to be set to 0.
Path: HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\options\Reminder
where 16.0 indicates the Outlook version.
Don't forget to restart Outlook to apply changes.
These settings can be overridden on the per appointment basis - you can simply set AppointmentItem.ReminderPlaySound property to false using VBA.
Simulate a button press with ExecuteMso.
https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
Hover over the button where you would add it to the ribbon/QAT. See text in brackets at the end.
Are the command codes for ExecuteMso documented?
Private Sub ExecuteMso_TextInBrackets()
' https://learn.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
' https://stackoverflow.com/questions/25610998/are-the-command-codes-for-executemso-documented
Dim oAppt As Object
Set oAppt = ActiveInspector.CurrentItem
Debug.Print oAppt.subject
ActiveInspector.CommandBars.ExecuteMso ("TextInBrackets")
End Sub
As with most things in life, the answer is a workaround. In this case, it's AutoHotkey to press the keys for me (ALT F, T, down x 9, ALT P, Enter):
;WIN-O toggles the Outlook alarm sound setting
#o::
SetTitleMatchMode,2 ;inexact match
WinGetActiveTitle, MyWindowTitle
If WinActive(" - email#company.com") ;Poor way to "prove" we're in Outlook
{
;MsgBox, We're in Outlook
Send !ft{Down 9}
Send !p{Enter}
}
Return

How to access "message bar" in Outlook?

When I enable "Out Of Office" automatic messages in Outlook 2010, the "message bar" is filled in with a warning text. I would like to use such a feature to inform the user of my own feature being enabled.
I cannot find any reference to programmatic access to this bar. I found something about the statusbar, but it is not usable in VBA in Outlook.
I am not even sure the proper English name of this feature is "message bar"; I am referring to the same bar which in Word is used to inform user that a document is "dangerous" because coming from internet.
Is this message bar exposed in VBA for Outlook?
I tried finding other methods to inform the user, so I started studying the Ribbon: if I could make my own tab visible I could use it as a "message bar", but Ribbon is managed by Outlook differently from other Office programs, so most of examples available around are not applicable/working in Outlook.
I was able to programmatically create a tab and add a button to it, but then I can't make the tab visible.
I also tried using property "position" of the commandbar: not just msoBarTop but also msoBarBottom or msoBarPopup, but Outlook ignores my efforts.
But maybe managing the Ribbon in Outlook with VBA should be addressed in a separate question (there are some questions about it here, but I could not find useful tips for me; I have no access to VB VSTO).
The area you are referring to is used to implement Mail Tips. Although you can create custom ones through the Exchange Admin Center , they cannot be interacted with via code.
Manipulating Ribbon controls to show states or user messages is not really recommended, as the Ribbon is generally a static thing (except in case of menus, dropdowns and Galleries).
If your goal is to show a transient alert, a better approach would be to use the Windows SDK to show Windows notifications. If having your alert hosted in Outlook is of the utmost importance, then look into using Form Regions or an add-in with Task Panes to display your messaging. Or even a simple VBA MessageBox or User Form.
Also note that your usage of the CommandBar is really only applicable to Outlook 2007 and earlier - there are no more CommandBars in newer versions, just the Ribbon.

Communicating with Outlook 2013 add-in (Skype for Business)

I have a task involving Outlook 2013 and the Skype for Business add-in (formerly known as Lync).
The add-in has a button which changes an appointment into a "Skype meeting".
Pic of button
Upon clicking this button, the following is added to the email body.Pic of default text
My goal is to change this default text (it isn't editable anywhere else). The way I planned to do this is by creating a macro to call the same function which the "Skype Meeting" button does, and then edit the body of the message after the default meeting text has been placed.
I checked for the "name" of the button via the 'Customize the ribbon' window, and within the 'Skype Meeting' group the 3 buttons had the same description (Macro: OnUCAppointmentOnAction)
Using VBA's object explorer I found the details of the method OnUCAppointmentOnAction:
Sub OnUCAppointmentOnAction(asIRibbonControlPtr As Object)
Member of UCAddinLib.UCAddinCallbackInterface
method OnUCAppointmentOnAction
I have added the library reference within VBA to UCaddin.dll (it's called Office Communicator W14 Type Library), yet when I try to call the macro OnUCAppointmentOnAction I get the error "Sub or Function not defined"
Where am I going wrong? Is there is a better way?
Don't do that. That method is implemented by the COM object implementing the IDTExtensibility2 interface that Outlook creates on startup when it loads the addin. In theory, you can do the same, but nobody known what will happen if there are two instances of the addin object instantiated. Simulate a click on the button, then edit the appointment body.