Outlook VSTO - Allow specific AD group to see ribbon - c#

How can I programmatically restrict the VSTO Add-in Ribbon visibility to a specific AD group only? Can this be controlled directly from the Ribbon XML itself? The plugin is distributed to entire org, but need the ribbon visibility to change by AD group

No, but your own code can easily perform the check and show/hide the ribbon using the getVisible callback specified for your ribbon.
Would be a good idea to perform that check asynchronously and cache the check result before the ribbon is requested by Outlook. If the check completes after the ribbon is returned, call RibbonUI.Invalidate(), which would case Outlook to invoke your getVisible callback again.

Related

How can I add dynamic button to Office Ribbon

How can I add dynamic toggle button to Office Ribbon? Button names are dynamic, they can change, so how can I make the buttons dynamic?
All dynamism is possible for ribbon toggle buttons via callbacks. You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks that the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method. You can also find the InvalidateControl method helpful which invalidates the cached value for a single control on the Ribbon user interface.
The toggleButton control has the getPressed callback which allows you to specify whether the toggle button control is pressed or not. It has the following signature:
C#: bool GetPressed(IRibbonControl control)
VBA: Sub GetPressed(control As IRibbonControl, ByRef returnValue)
C++: HRESULT GetPressed([in] IRibbonControl *pControl, [out, retval] VARIANT_BOOL *pvarfPressed)
Visual Basic: Function GetPressed(control As IRibbonControl) As Boolean
Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

Programmatically get the list of the ribbons using VSTO add-in

I have created a C# VSTO add-in with Visual Studio 2019 that receives commands from a socket connection and it can insert text, modify buttons only in my ribbon using office Interop.
I want to know two things.
How can I get the name of all the ribbons (Home, Insert, Design,
....) programmatically?
Initiate a mouse click (for example click Bold button in the Home tab) on any other ribbons than the one I created.
For the 2nd question, I want to use office add-in only, not by simulating keypress/mouse event.
How can I get the name of all the ribbons (Home, Insert, Design, ....) programmatically?
There is no trivial way for getting this job done. You can try using Accessibility API. 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.
Initiate a mouse click (for example click Bold button in the Home tab) on any other ribbons than the one I created.
You can use 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. On failure, it returns E_InvalidArg for an invalid idMso, and E_Fail for controls that are not enabled or not visible.
Application.CommandBars.ExecuteMso("Copy")
Accessibility API (as Eugene mentioned) is pretty much the only way to drive Outlook Ribbon and its controls. Keep in mind that since Microsoft has never documented the controls and their ids, they are subject to change between the versions.
If using Redemption (I am its author) is an option, it exposes SafeExplorer and SafeInspector objects that expose the ribbon and its controls using Accessibility and low level Windows API.
Redemption.SafeExplorer sExplorer = new Redemption.SafeExplorer();
sExplorer.Item = OutlookApplication.ActiveExplorer;
foreach (var tab in sExplorer.Ribbon.Tabs)
{
MessageBox.Show(tab);
}

Add a button to Outlook message ribbon

I'm totally newbie in Office Add in Development.
Started few hours ago :)
Office version: 2016
I would like to create an add-in, with a button that will allow me to synchronize my email with my custom program and "flag" it to avoid a new synchronization in the future.
For that, it would be necessary to:
add a button (it seems simple to me, but by following this link, I did not manage to see the button when debugging in Outlook)
I would like the button is present in the ribbon that appears when you open an email, and only down (it would prevent a synchronization of several emails at once) - and I can not find the name of the adequate control. There is a list of Excel files (here) but which corresponds to the one of the opening of the mail message?
perform any action when the user clicks the button - I guess that's a simple event of the button, but how can I get the opened message data and metadata (sender, to, cc, subject ...)
"flag" the email, so as to avoid a second synchronization. The ideal is to add an icon to the email in the list of emails, as is done for an email containing attachments etc ...
I know I'm asking a lot, but I'm not asking to get the job done, just to be able to steer in the right direction. So if you have tutorials, articles etc ... to help me, it would be great.
Thank you
N.B.: Copy of this question has been posted in VSTO forum here
To create a custom ribbon UI, VSTO provides two possible ways:
Walkthrough: Create a custom tab by using the Ribbon Designer
Walkthrough: Create a custom tab by using Ribbon XML
To keep a separate state for the control for each inspector window separately you need to implement ribbon callbacks and call the Invalidate or InvalidateControl methods of the IRibbonUI interface. Read more about these methods in the following articles:
OfficeTalk: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon User Interface (Part 1 of 2)
OfficeTalk: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon User Interface (Part 2 of 2)
The Fluent UI (aka Ribbon UI) is described in depth:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

Can VSTO update/refresh an Office 2007 Ribbon XML menu control

I am already using the Ribbon with XML to add controls to the inspector of a received mail item in Office 2007.
I now want to add a menu/Combo box as well. The problem is that it takes too long to generate the list of items.
Basically is it possible to let the Ribbon be generated and then add the items once they are ready?
I envisage something like:
Create the ribbon with an empty menu
Start a new thread and send it off to get data (thread safe stuff no office)
Get back on the office thread and add the list to the menu
Is it possible to do this?
IMHO, it is difficult to achieve. In Standard ribbon control, values are rather static. They are loaded in to the controls before the ribbon is actually shown. I am not sure if there is a way to intercept it.
It appears it is possible with the use of a DynamicMenu control. Using a numbered list for my answer here is what I did.
Let office show the UI (in this case an Outlook Inspector)
Get the text of the Email Item and then start a new thread to process
When processing is finished get back onto the main UI Thread.
In the Ribbon XML an "empty" DynamicManu exists with a callback for its data
If the result is there is no data then call invalidate and the getVisible call back sets the control to false. Control dissappears.
If there is data to add then invalidate and allow the control to now read the data in the callback.
I would like to thank my secretary for editing my post

Querying properties and handling events for built-in control in Outlook Add-in

Is it possible to handle events for built-in controls in Outlook and/or query their values?
I'm coding for Outlook 2010 and 2013. I would like to know when a user changes a value of a control on the ribbon and on the File/Info pane when composing an email and get the values of these controls.
The only way to do anything with the built-in Ribbon controls is to repurpose them.
See http://msdn.microsoft.com/en-us/library/dd944181(v=office.12).aspx

Categories