VSTO Addin disable builtin outlook button on Appointment (Recurring) - vsto

I am developing an Outlook Addin (VSTO, C#). I created the Addin with the following steps in VS: New->Project , then
From all what I learned in the meantime I fear that this DOES NOT create a COM-AddIn. But all tutorials listed below refer to COM AddIns.
I am looking for a step by step tutorial of how I can disable the builtin OUtlook Button which converts an appointment into a recurring appointment.
I already read a lot about fluent ribbons, like here
Programmaticaly disable existing button in outlook compose window ribbon
https://learn.microsoft.com/de-de/office/vba/library-reference/concepts/overview-of-the-office-fluent-ribbon
But I am just no able to put this into action for my purpose:
1.) I implemented in my Addin Class
public partial class ThisAddIn : Office.IRibbonExtensibility
...
string Office.IRibbonExtensibility.GetCustomUI(string RibbonID)
{
throw new NotImplementedException();
}
I set the breakpoint on the Exception. But running the addin (in Debugger) never stopped at that point.
I tried what is mentioned here:
IRibbonExtensibility GetCustomUI not called
I added [ComVisible(true)] to the VSTO AddIn Class. Does not work either. I also made sure that the Addin is still loaded.
2.) I am not sure how I could that with Outlook. It says that Outlook has several xml files (one per inspector?)
3.) I am not sure whether I would be able to dynamically change the buttons. Athough the second tutorial talks about that, but i am not sure if callbacks are the right concept here, because my application activley wants to decide when a button should be active/inactive, so there is no waiting for a callback to happen?
I know that the links provided above contain step-by-step tutorials. But there are just too many open questions to these tutorials.

You have already found a complete guide on how to repurpose a ribbon button. Just use command tag with the getEnabled attribute defined in your ribbon XML markup. For example:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<commands>
<command idMso="Permissions" getEnabled="OnGetEnabled" />
</commands>
</customUI>
You can repurpose built-in ribbon controls, see Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.
VSTO provides two ways of customizing the Fluent UI:
Walkthrough: Create a custom tab by using the Ribbon Designer
Walkthrough: Create a custom tab by using Ribbon XML
Unfortunately, the UI designer doesn't support all the features of the Fluent UI. So, you need to stick with a raw XML markup described in one of the articles mentioned above.

Related

How do you add a 'public partial class ThisWorkbook' to a VSTO application in C#?

I am trying to add an ActionPane to an Excel VSTO Add-in. I need to access the ThisWorkbook.ActionsPane collection to add my action panes.
The Microsoft documentation at:
https://learn.microsoft.com/en-us/visualstudio/vsto/how-to-add-an-actions-pane-to-word-documents-or-excel-workbooks?view=vs-2019
says:
To show the actions pane, add the user control to the Controls
property of the ThisDocument.ActionsPane field (Word) or
ThisWorkbook.ActionsPane field (Excel).
Add the following code to the ThisDocument or ThisWorkbook class as a
class-level declaration (do not add this code to a method).
This implies that I need to add a ThisWorkbook class to the VSTO solution. My questions are:
What base class contains the ActionsPlane collection?
How would I add a class derived from this base class to my VSTO?
Some on-line examples of a ThisWorkbook class contain regions that are designer generated.
My workload includes every VSTO item available. There are no Excel items at all under 'Add New Item' or 'Add New User Control' in Visual Studio 2019. Beyond the Ribbon Bar, there are no designers for VSTO.
The only way that I see to do this is to add a ThisWorkbook class manually.
Am I correct in saying that any designers that may have existed in previous versions of Visual Studio, no longer exist in Visual Studio 2019?
You need to differentiate document-level and application-level add-ins.
An actions pane is a customizable Document Actions task pane that is attached to a specific Microsoft Office Word document or Microsoft Office Excel workbook. The actions pane is hosted inside the Office task pane along with other built-in task panes, such as the XML Source task pane in Excel or the Styles and Formatting task pane in Word. You can use Windows Forms controls or WPF controls to design the actions pane user interface.
Read more about Actions panes in the How to: Add an Actions Pane to Word Documents or Excel Workbooks article if you are developing a document-level add-in.
If you are developing an application-level add-in you may be interested in using Custom task panes. Task panes are user interface panels that are typically docked to one side of a window in a Microsoft Office application. Custom task panes give you a way to create your own task pane and provide users with a familiar interface to access your solution's features. For example, the interface can contain controls that run code to modify documents or display data from a data source. See Walkthrough: Automate an application from a custom task pane to get started quickly.

In Outlook, composing a message, can I visually tag it somehow in VBA?

I have a some VBA that will file an outgoing message as a Task (and do some other things) if I tag it. One way I tag is by calling a macro that sets a UserProperty; I have assigned the macro to a button on the command bar.
I would like to visually mark the message as having been tagged before I send it, and then implement a toggle, but I'm struggling to find a way of doing it. So keeping the button depressed, or highlighted, would work but I can't see how to do this in the Fluent UI stuff. Alternatively, I'd like to add something to the area to the right of the "pop out" "discard" buttons at the top of the message.
I tried adding a category to the new message, but this is not displayed in the pane. I do have a UserProperty assigned, but I don't know how to display that either.
Any ideas?
Many thanks
VBA doesn't allow customizing the Fluent UI. You need to develop a COM add-in instead. To implement a toggle button on the Ribbon you need to define callbacks where you may check the user property value and update the UI accordingly. The Fluent UI is described in-depth 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)

How to add a group to a (VBA) custom ribbon without xmlns/idQ?

Situation:
Users have an existing custom ribbon that is added via a .PPAM (combination of VBA macros and Ribbon customization XML).
We want to add a group to that custom ribbon via our managed COM add-in
For custom ribbons from other managed COM add-ins this is feasible via the xmlns:foo="bar" & idQ that can be extracted from the customUI Link
Complication:
Custom Ribbons from non-managed add-ins seem to have no xmlns namespace, they do not show up in the customUI
Even via PowerPoint/Office the user can not customize those ribbons.
Any idea how we could achieve adding buttons?
We can request changes to the non-managed/VBA add-in.
VBA add-ins don't have their own namespace by default, but can have one. If you create a custom namespace, then multiple VBA add-ins can share the same tab on the ribbon, for example.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
xmlns:nsMySpace="SomeName">
Then to create a new tab that other add-ins can share:
<tab idQ="nsMySpace:MySpace_Tab" label="MyTabLabel">
In addition to Steve's answer we've discovered that VBA add-ins have a default namespace even when none is specified in their customUI.
You can extract the namespace by adding a control from the ribbon to the Quick Access and then exporting the UI Customizations. The resulting file should show:
<mso:cmd app="PowerPoint" dt="1" />
<mso:customUI xmlns:x1="C:\Users\USERNAME\AppData\Roaming\Microsoft\AddIns\Addin.ppam">
So the default namespace seems to be the complete Path to the add-in.
From a high perspective two add-ins can share a ribbon tab for controls because they are loaded into a single PowerPoint instance. When you develop a macro enabled file with a custom UI - only this file can be opened at the same time. But two add-ins can be run for the file/template. That's why idQ is intended to use by add-ins.
You can read more about the Fluent UI (Ribbon UI) in the following series of articles in MSDN:
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)

Customize Office Ribbon programmatically

I am writing an addin to Office (both 2007 and 2010), and have so far used the Fluent Ribbon XML to customize the different ribbons.
The problem I am having now with that approach, is that I want to have a bit more flexibility in my code, and have different modules add more buttons to the ribbon, without hard coding them in XML - The addin is composed of several disconnected modules, and it doesn't "know" exactly what ribbon elements it might need.
Is there a way to do it? I bumped into the LoadCustomUI method on the Application object, but it is not available in C#. Looks like just what I might have used for my scenario.
For .NET 4 (which I assume you're using because of targetting Office 2010), you'll override CreateRibbonExtensibilityObject. More info can be found on this page: Ribbon Object Model. This is also a good read: Updating the Controls on a Ribbon at Run Time.

Outlook 2007 Ribbon and MVP

I'm working on outlook 2007 VSTO Addin.I have added a Ribbon with a button. I am trying to raise an event on button click.On NewInspector event of Application.Inspectors collection I should be able to hook on to this ribbon event in the Presenter.
The questions is how to get hold of Ribbon of Inspector opened. I tried Globals.Ribbons.MyRibbon to do so.Strangely it works only for the first inspector. I also tried Globals.Ribbons[inspector].MyRibbon.
Looks like when NewInspector is created the Ribbons Collection has 0 Items and Ribbon load happen only after NewInspector event handler is executed.
Is there any event to know when a ribbon loads OR Is there any alternative way ,where i can keep the business logic in Presenter instead of having it in ribbon view.
The answer is with much effort..
As far as I can tell the ribbon is not exposed through vsto or com interop, it is also stateless, so the ribbon will be loaded once no matter how many inspectors are shown.
It took me a long time to gracefully solve this issue, and it is pretty complex code. I also should mention that I chose to tackle the problem using ribbon XML rather than the designer, I found the designer too restrictive.
The guts of it is you have to create a custom IRibbonExtensibility implementation, then rewrite the callbacks in the ribbon XML, so they will callback to methods on your IRibbonExtensibility impl.
You then have to handle the loaded event, and the new inspector event so you can relate the two.
There is actually a lot more to it and you can check out my code in the VSTO contrib project.
http://vstocontrib.codeplex.com/SourceControl/changeset/view/b35f26fdca15#src%2fOutlook.Utility%2fRibbonFactory%2fRibbonFactory.cs
If you are building a MVP framework for VSTO drop me an line as I would be interested to see what you are doing.