Outlook VSTO Add-In loads, but ribbon doesn't - c#

I'm making an Outlook VSTO Add-In with a ribbon and the ribbon stopped loading. I'm using the Ribbon (Visual Designer). It was loading fine, I made some code changes, fired up a new session, and it wouldn't load. There is no "Add-Ins" item in the ribbon.
I think the problem is in my Outlook, not in my project.
I created a new project to make sure there wasn't something wrong with my larger project, using the most basic code with no code in the addin class and only a single group in the ribbon. It still won't load.
ThisAddIn_Startup is firing, so I know the addin is loading in Outlook
I've tried both Ribbon Designer and XML
RibbonType is set to Microsoft.Outlook.Explorer
I've deleted all .vsto files and removed references in the registry
I've rebooted

First of all, I'd suggest making sure you don't have any ribbon UI errors at runtime. Here is what MS states:
By default, if a VSTO Add-in attempts to manipulate the Microsoft Office user interface (UI) and fails, no error message is displayed. However, you can configure Microsoft Office applications to display messages for errors that relate to the UI. You can use these messages to help determine why a custom ribbon does not appear, or why a ribbon appears but no controls appear.
See How to: Show Add-in user interface errors for more information.
Make sure that you did all the steps described in the following articles (one of them):
Walkthrough: Create a custom tab by using the Ribbon Designer
Walkthrough: Create a custom tab by using Ribbon XML
If you use the ribbon XML approach you can set up a breakpoint in the ribbon's getCustomUI callback to make sure the callback is invoked and what ribbon XML is returned.

Related

VSTO How to determine if Outlook Ribbon is in Simplified or Classic mode

How can one programmatically determine if an Outlook ribbon is displayed in Simplified or Classic mode? Is there a related property and/or event which a VSTO add-in can access? Have not been able to find any info on this. This would be used to adjust the label and image of our ribbon buttons depending on the ribbon mode via the callbacks provided in our ribbon XML declarations. But maybe there is another way to do this?

Is there a workaround or alternative to IRibbonControl.Context to access the correct window and workbook in Excel 2016 or newer?

There are existing posts on SO about related topics, and there are support requests on MSDN that are unsolved/unrepaired. It sounds like the "right way" doesn't work, so I'm wondering there is a workaround.
Let me describe what I perceive to be "the right way" that doesn't work, and maybe you have an alternative path that will work.
I can create an Excel VSTO plugin in Visual Studio, create a custom Ribbon.xml and Ribbon.cs file, and then open multiple workbooks which appear as different windows. Per other SO posts, I can hook into the Application_WindowActivate event and call Invalidate() on my ribbon, forcing a refresh of all the callbacks. The ribbon will reflect the state of the Active Window... and so will every other instance of the ribbon in other windows. As a result, the Ribbon that appears in every window is the same Ribbon. If I have a CheckBox or a Button with a Pressed attribute or anything else stateful, those states will propagate to every open Excel window.
This can be avoided by running Excel with the excel /s parameter which appears to create a new process with its own SDI - but this is not a user-friendly solution.
It looks like what you're supposed to be able to do during an onAction ribbon callback is access the IRibbonControl parameter's Context property, which is supposed to be the correct Excel.Window object. In theory this would present either only the Window you are activating, or would execute for each open Window. And with the correct Context you could execute functions that provide different states back to the Ribbon. And then maybe in one Excel window, you ribbon could have a Pressed Button, and in the other window, an unpressed Button. Except it doesn't work.
When I call Invalidate I get two callbacks (not sure why, the MSDN says it might be a bug) both for the newly activated window, and I execute logic to update the state of active window's ribbon. And then the previous window's ribbon updates the same way.
If this is the way it is, fine. We'll tell our users that they may see some funky Ribbon changes on inactive windows but that it will always be correct on the active window. We can deal with that. But if there is a way around this problem that could make it appear as though the Ribbon had different states on a per-workbook/window basis... that'd be really cool.
You are on the right avenue. Only the active window gets callbacks invoked and its values refreshed. You must switch to another Excel window if you want your ribbon UI invalidated. For each of the callbacks 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 may also consider caching UI settings in custom properties. And as soon as a custom property is changed you may trigger UI updates.
Read more about the Fluent 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)
Also, you may find the folliwing links helpful:
Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)
Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)

Outlook 2010 VSTO AddIn tab customization not showing [duplicate]

I've got a minimal VSTO Addin for Outlook 2010 with a ribbon. My only goal is to display a ribbon (created via designer) with no functionality. From what little I can tell from MSDN ribbons should just automatically be displayed by default, perhaps with tweaking ControlIdType/CustomId properties for tabs.
Alas, tweaking these properties does nothing -- Outlook loads and displays no tab. A simple message box displayed in the ribbon loader reveals it never is triggered. Additionally, I haven't seen any information resources (tutorials, walkthroughs, overviews, etc..) that say anything about needing to manually tell Outlook to display tabs.
How do I get the tabs displayed?
Is there a good resource other than MSDN that's good for VSTO newbies?
To get your ribbon displayed, on the base ribbon in your code change the RibbonType property to be Microsoft.Outlook.Explorer.
What fixed it for me (without starting a new project), in the Ribbon1.vb ribbon design, I clicked on the the Ribbon1 name above the ribbons 'File' button, in the properties pane, clicked on tabs (collection), under the heading 'Design' I changed the name (from Tab1) to something else.
Clicked ok, tested by clicking F5 and it worked. Hope this helps someone else.

Create Add-In for Outlook 2013 for add a Button

Good morning,
my company is looking for a solution in order to distribute an add-in for Outlook 2013 that add a button in the ribbon. I want to create an add-in for Outlook 2013 and I saw that is possible using Visual Studio (I use VS 2013 or 2010) but I don't understand how to add a button in the ribbon (in particular in Home section) and execute a macro when I click on the button (the macro is already created). I read this tutorial https://msdn.microsoft.com/en-us/library/cc668191.aspx and this worked. Someone can help me with some piece of code(c#)?
Thanks for your help
VSTO provides two main ways for customizing the Ribbon UI:
Using the Ribbon designer. See Walkthrough: Creating a Custom Tab by Using the Ribbon Designer for more information.
Using the Ribbon XML markup. See Walkthrough: Creating a Custom Tab by Using Ribbon XML for more information.
You need to specify the idMso attribute of the built-in tab if you need to add your custom controls there. See Office 2013 Help Files: Office Fluent User Interface Control Identifiers for control IDs.
Finally, I'd suggest moving your VBA macro to the add-in. It will improve the overall performance and allows to use the BCL classes (a wide varioety of controls and components) for getting the job done. Moveover, you will be able to deplay the add-in easily. VBA macros are not designed for deployiong on multiple PCs.

Trigger a call to IRibbonExtensibility.GetCustomUI() to force a ribbon UI refresh

I am developing an Office add-in. Due to some limitations of ribbon controls (e.g. menuSeparator has no visibility control or splitButton cannot host a dynamicMenu only a menu), I need to be able to cause the Office app to reload the ribbon by repeating a call to my add-in's IRibbonExtensibility.GetCustomUI.
Is this possible?
As far as I know ribbon add-ins, this would require to stop and then restart your add-in. There must be a way to do so given that one can access the list of add-ins in outlook. you could run another instance of your add-in which would first close the previous one, then return the updated ribbon XML. But this means that it would not be applicable while the user is clicking on the ribbon's components, and you would have to save all your data somewhere and then read it to restore the add-in status. In addition, the user may see the ribbon disapearing and appearing again, which may not be appreciated.
Would the Ribbon.Invalidate() method work for your use case? I frequently use it to refresh the ribbon when I've dynamically added/removed items.
For example, in the Ribbon c# file (Ribbon1.cs by default):
this.ribbon.Invalidate();
When the ribbon needs to be refreshed. This assumes you've set this.ribbon in the Ribbon_Load method.

Categories

Resources