I am trying to set a transparent icon for my Excel add-in with the RibbonX API. This is my XML:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" loadImage="gui_LoadImage">
<ribbon>
<tabs>
<tab id="CBtab" label="2019CBMaster">
<group id="visualizationGroup" label="Visualization">
<button id="btnHistogram" label ="Press here" enabled="true" screentip="Press and see how magic happens" image="icn_btnHistogram.jpg" size="large"/>
</group>
<group id="NewGroup" label="2019NewGroup" >
<box id="bxBo">
<button id="btnNew" label="Press" image="icn_btnHisto.jpg" size="large"/>
<menu id="mnMenu" image="btn_img_random.jpg">
</menu>
</box>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
this is the sub that is setting the picture: for my testing purposes, it ignores the xml parameters and simply loads a 'fixed' picture:
Sub gui_LoadImage(ImageName As String, ByRef Image)
Set Image = stdole.LoadPicture("C:\Office 2010 Developer Resources\icons\gg.ico")
End Sub
I saved gg.ico in GIMP as 24 bpp and 1 bit alpha ico file. I also tried external ico-s and they did not display as well.
As you have understood from above, the icons are not displayed as if they were completely transparent.
Could you help?
Also, is this RibbonX API still supported? I am wondering because I have difficulties doing a pretty basic thing and can find little to no documentation. If not, what are the modern frameworks for developing Excel Add-ins with customizable ribbons?
Thank you.
Custom Ribbon UI icons can be transparent. I believe they must be .png files. Here are details on the UI Ribbon icon settings, which includes transparent backgrounds.
https://learn.microsoft.com/en-us/office/dev/add-ins/design/add-in-icons
REVISION
In custom UI editor, you can import your image files and then just reference the file names in the XML code. The file type and whether or not the image itself has a transparent background is what I believe determines whether or not it appears transparently on the ribbon. This is what the XML would look like. <button id="customButton1" label="Label 1" size="large" onAction="Macro1" image="picture1" />
In looking at your XML code, I see that you have the file extension included in with the images. I do not include the file extensions with my custom image icons. In the Custom UI editor that I linked, you can add import the image file, which appears in the side pane, then you reference only the file name in the XML (no file extension). I also believe is the file type itself and whether or not the image actually has a transparent background that determines whether or not it appears transparently in the ribbon. jpg files cannot be transparent, so that may be your problem right there. If your UI editor cannot accommodate PNG files, try using GIF. The icons are so small; image quality shouldn't be an issue.
Here is an example:
<splitButton id="splitButton2" size="large" >
<button id="InsertTools" label="Insert" image="InsertTools_Transparent" />
<menu id="menu2">
<button id="buttonInsertMultiSheets" onAction="ModRibbon.Run_InsertMultipleSheets" label="Insert Multiple Sheets" screentip="Add multiple worksheets at one time. An input box will appear for you to enter the number of sheets to be added." image="WorksheetAddMultipleSheets" />
</menu>
</splitButton>
Here are some of my personal notes from when I was learning that may or may not be helpful for you.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<backstage>
<button id="MyCustomButton1" label="My Macro"
imageMso="HappyFace" isDefinitive="true" onAction="ModRibbon.Run_Macro1"/>
<!-- 'button id' each must be unique -->
<!-- 'My Macro' is the text that will appear on your button -->
<!-- Use 'imageMso' or 'image' to include a picture on your button. -->
<!-- 'imageMso' uses built-in Office images; do not insert into this file as icons. -->
<!-- 'image' uses your own image as your button's icon. Insert it into this file as an icon. -->
<!-- 'HappyFace' is the name of the built-in Office image (for custom images, enter the file name). -->
<!-- 'ModRibbon' is the name of the VBA module in which you will paste this call-back sub. You can name this anything. -->
<!-- 'Run_' is a custom prefix added to the macro name, so you don't have to rename your macros. -->
<!-- 'Macro1' is the macro that should be run when the button is clicked. -->
</backstage>
</customUI>
With the Custom UI editor I use, the callback would be:
'Callback for buttonInsertMultiSheets onAction
Sub Run_InsertMultipleSheets(control As IRibbonControl)
End Sub
From your code, it looks like you need a call to load the image as well, so the customUI control has two callbacks:
Sub LoadImage (imageID As String, ByRef image)
Sub OnLoad(ribbon As IRibbonUI)
If you also have a [Content_Types].xml, then the default type is PNG and you need to add a line at the very end of the file, but before , and then save your changes.
<Default Extension="jpg" ContentType="application/octet-stream"/>
The recommended file format for icons on the Ribbon UI is PNG. Microsoft Office Ribbons and toolbars support ICO, BMP and ICO files. So, I'd suggest converting your VBA macros to the COM add-in where you can easily load such images.
You may find the Graphics formats for Microsoft Office add-ins article helpful. 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)
Related
I tried to customize the Office ribbon for one of my Office documents, as explained in chapter "To customize the Fluent UI by using Office Open XML Formats files".
It should theoretically add a new tab and one button, but when I open this document I always get this error (NB: I activated the Office option to see errors with Backstage view (File) > Options > Advanced Options > General > Show add-in user interface errors):
Error detected in custom UI XML code ... Line 1 Column ... Error code 0x80070057 - Incorrect parameter.
Here is the popup containing the error message (NB: I have Office in French language):
And the new tab does not show up at all.
It failed with an Excel document, but I also tried to do it with Word and PowerPoint, and got exactly the same error.
Here are the changes I did to Classeur1.xlsx to add the tab (renaming its suffix to .zip, manipulating its content, and renaming it back to .xlsx):
In _rels/.rels, I added this line before added this line before </Relationships>:
<Relationship Type="http://schemas.microsoft.com/office/2006/relationships/ui/extensibility"
Target="customUI/customUI.xml" Id="customUIRelID"/>
I created customUI/customUI.xml:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
<tabs>
<tab id="MyTab" label="My Tab">
<group id="MyGroup" label="My Group">
<button id="MyButton" label="MyButton" onAction="MyMacro"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
NB: I know that the subroutine "MyMacro" must also be created and the Excel file is to be saved as type .xlsm, but I just want to propose the minimal case to reproduce, clicking the button is not the problem here.
My Excel, Word and PowerPoint versions: Office 365, Version 2008 (build 13127.20408 Office "click-and-go").
EDIT: here is the screenshot of version (NB: 2 days after my question, it has been upgraded automatically to version 2009 Build 13231.20262), and I haven't got the error now
The error is that <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> is not valid for the version "2008" for subscription 365 -- I don't pretend that it's Office 2008, it's just what I saw, it's like now "2009" (see screenshot in my question) -- even if Steve Rindsberg doubts that versions 2008 and 2009 can appear, sorry to not have taken a screenshot -- hopefully I could find this screenshot mentioning a version "2008" in this Windows blog post:
Instead, I used the namespace <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> combined with relationship using the Relationship namespace http://schemas.microsoft.com/office/2006/relationships/ui/extensibility>:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="MyTab" label="My Tab">
<group id="MyGroup" label="My Group">
<button id="MyButton" label="MyButton" onAction="MyMacro"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Now, I can successfully see "my tab" when I open Classeur1.xlsx:
Reason
Ron de Bruin mentioned at https://rondebruin.nl/win/s2/win001.htm, while presenting the Office RibbonX Editor, that one of the two versions must be selected:
Insert Office 2010+ Custom UI Part
Insert Office 2007 Custom UI Part
So I guess that there is a corresponding namespace according to the Office version (whatever it's under 365 subscription or not). Note that there is also a different namespace for _rels\.rels mentioned in [MS-CUSTOMUI] and [MS-CUSTOMUI2] Microsoft standards.
2010+ ([MS-CUSTOMUI2])
custom UI: <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
Source relationship: http://schemas.microsoft.com/office/2007/relationships/ui/extensibility
2007-2009 ([MS-CUSTOMUI])
custom UI: <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
Source relationship: http://schemas.microsoft.com/office/2006/relationships/ui/extensibility
(*) PS: I am not sure to have correctly tested if the combination of both namespaces for 2010 did work or not for my version "2008" with subscription 365. Steve has said in the comments that it should have worked because it's subscription 365. I can't test anymore for "2008" because my Office version was automatically upgraded to version 2009, and 2010 namespaces work.
I created a basic custom Excel ribbon tab with 5 buttons. When I edit the custom ribbon (using Office RibbonX Editor) everything works fine when I launch the Excel file for the first time after the ribbon edit.
But the problem is when I close my Excel file and I want to reopen it again (for the second time), there's no single sign my custom ribbon tab ever existed. My custom tab keeps disappearing. When I open Office RibbonX Editor again, the XML file is also empty. Is this problem fixable? I want to be able to close my Excel file, open it again, and use my custom ribbon as many times as I want.
Here is the XML code of my custom tab:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="voetbalOpstellingTab" label="Voetbalopstelling" insertBeforeMso="TabHome">
<group id="openMainWindowGroup" label="Home">
<button id="openMainWindow" image="home" size="large"
label="Open het hoofdscherm" description="Open het hoofdscherm"
screentip="Open het hoofdscherm"
onAction="ribbonTab.openMainWindow"/>
</group>
<group id="viewGroup" label="Weergeven">
<button id="openPlayersSheet" image="group" size="large"
label="Spelers weergeven" description="Geef de spelers weer"
screentip="Geef de spelers weer"
onAction="ribbonTab.openPlayersSheet"/>
<button id="openWedstrijdSheet" image="dashboard" size="large"
label="Overzicht weergeven" description="Geef het overzicht van wie, waar tijdens welke wissel heeft gespeeld weer"
screentip="Geef het overzicht van wie, waar tijdens welke wissel heeft gespeeld weer"
onAction="ribbonTab.openWedstrijdSheet"/>
</group>
<group id="actionsGroup" label="Acties">
<button id="openAddPlayerWindow" image="add-user" size="large"
label="Speler toevoegen" description="Voeg een speler toe"
screentip="Voeg een speler toe"
onAction="ribbonTab.openAddPlayerWindow"/>
<button id="openRemovePlayerWindow" image="remove-user" size="large"
label="Speler verwijderen" description="Verwijder een speler"
screentip="Verwijder een speler"
onAction="ribbonTab.openRemovePlayerWindow"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Can someone please help me?
Thanks in advance!
You are referring to some built-in controls on the ribbon. Make sure all of them are available when Excel is open. Otherwise, your custom UI will not be created.
Do you get Ribbon UI errors when your custom UI disappears?
By default, if an 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.
To show VSTO Add-in user interface errors
1. Start the application.
2. Click the File tab.
3. Click Options.
4. In the categories pane, click Advanced.
In the details pane, select Show VSTO Add-in user interface errors, and then click OK.
A security update may have caused this. See this:
https://www.youtube.com/watch?v=AhnOU-ulqNg
I have successfully made Word VBA and VSTO Add-Ins share ribbon customizations in the past using code like this:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load" xmlns:nsMvSample="Sample Namespace">
<ribbon>
<tabs>
<tab idQ="nsMvSample:TabAddIns" label="Sample Tab">
<group idQ="nsMvSample:MyGroup" label="Sample Group">
<button id="NewDocument" label="New Document" imageMso="FileNew" size="large" onAction="NewDocument_Click" supertip="Opens the Select Template dialog to create a new document."/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
I'm currently getting to know the newer Office Web Add-Ins. I'd like to slowly introduce them into my solution by moving commands one at a time from VSTO to Office Javascript.
Can a VSTO Add-In share ribbon customisations with the newer Office Web Add-Ins?
Can I use the same idQ syntax? If so, how do I setup the namespace?
I'm afraid not. Office Web Add-ins use an entirely different mechanism for defining commands in the ribbon. They support a more constrained set of requirements and controls (buttons and drop-down buttons).
Im running 2016 Standalone Excel (32bit version). I've been building a custom ribbon and so far so good. The documentation is pretty fluid and well written. However, I cant find any way to include menu 'section titles' as seen below:
Specifically referencing section titles like in the picture (i.e., 'Cell size', 'Visibility' etc). I've seen other Add-Ins emulate this, unless they are COM Add-Ins. Here is the documentation I reference: https://msdn.microsoft.com/en-us/library/dd911038(v=office.12).aspx
Is it out of date? I've tried adding 'Menu with Title' to my project but that doesn't even work. I've also tried adding <labelControl /> , and the ribbon doesn't even load when the labelControl is within a Menu.
Additionally, my version of Excel won't even display a <dialogBoxLauncher> so I'm concerned some things just aren't compatabile with my Excel version to begin with. I'm following the documentation easily and everything else has worked just fine. I even have a editBox in the ribbon I use and don't run into any 91 errors with it. So I know it's not me.
Can anyone duplicate this with the provided API? My ribbon is structured with XML, so I've reduced as much error potential as possible, is that my problem? Should there be run-time code implemented specifically for section titles?
Short snippet of my setup
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad">
<ribbon>
<tabs>
<tab idMso="TabHome">
<group id="GroupTextTools" insertAfterMso="GroupFont" label="Text Tools">
<gallery id="textcase_gallery" label="Case Select" columns="1" size="large" imageMso="WordArtInsertDialogClassic" onAction="TextCase_SwitchCase" >
<item id="textcase_CapsButton" imageMso="TextAllCaps" label="Uppercase" screentip="Changes selected cells to all uppercase" />
<item id="textcase_ProperButton" label="Propercase" imageMso="ChangeCaseDialogClassic" screentip="Changes selected cells to proper case" />
<item id="textcase_LowerButton" label="Lowercase" imageMso="FontSizeDecrease" screentip="Changes selected cells to all small case" />
</gallery>
</group>
</tab>
<tab id="CustomTab" label="*removed*" insertAfterMso= "TabDeveloper">
<!--
GROUP A
-->
<group id="GroupFileOptions" label="File Options">
<button id="fileoptions_CloseButton" label="Close && Reopen" onAction="RunMacro" imageMso="SourceControlCheckIn" size="large" screentip="Saves Document, Closes && Reopens immediately"/>
<menu id="exportingmenu" label="Exporting" imageMso="FileCheckOut" size="large" screentip="Exporting Options">
<menu id="exportmenu_AsRange" label="As Range"> <!-- This is where I would like section Titles to be instead of another menu -->
<button id="exportmenu_range_CSVCButton" label="To CSV w/commas"/>
<button id="exportmenu_range_CSVSButton" label="To CSV w/spaces"/>
<button id="exportmenu_range_PDF" label="To PDF"/>
</menu>
<menu id="exportmenu_AsSheet" label="As Sheet"> <!--Goal is for this to be a section title, where I tried putting a <labelControl> -->
</menu>
</menu>
</group>
<!-- .... -->
</tab>
</tabs>
</ribbon>
</customUI>
After some trial and error, and an involuntary push from David Zemens by troubleshooting my errors, I've found that by cross referencing all the things I've tried with their Parent Elements, the only one that makes logical compiling sense is a <menuSeparator>, which just so happens to have a 'title' attribute. So by setting that you get a beautiful section title as shown:
<menuSeparator id="someID" title="Test title"/>
I managed to put a menu title only on a dynamicMenu via the getContent callback, which means the xml is defined in VBA as a piece of xml string, not in the customUI xml.
Most comprehensive documentation that I found so far on customUI interfaces is on https://msdn.microsoft.com/en-us/library/dd911038(v=office.12).aspx, however the references are pointing only to 2007. This link contains a much more extensive list of controls and options with extra controls for Access as well http://www.accessribbon.de/en/?Access_-_Ribbons:Ribbon_XML___Controls
I'm trying to lock down PowerPoint and I can get rid of some of the commands by using some ribbon-customization xml and group policies. But I need to remove or disable two more options.
PowerPoint Options - This button shows when you click on the Office icon
This item is also available in Word (Word Options) and Excel (Excel Options), so it should be the same solution.
In Office 2003 I could remove any item I wanted by deleting objects from _pptApplication.CommandBars.
Update: I can now disable Quick Access Toolbar with group policies. But I could not find anything there for "PowerPoint Options".
Thanks
It seems like there is no "official" way to do this so I created a workaround for my (controlled) environment.
Basically I check the screen for when the "office ball" turns dark orange and then shows a topmost form exactly where the "PowerPoint options" button is.
I anyone has a better solution I would like to know!
It can be disabled (not hidden) in PowerPoint/Office 2007 with some customUI-xml and the id "ApplicationOptionsDialog"; see http://excelusergroup.org/blogs/nickhodge/archive/2008/02/03/ribbon-step-by-step-part-3-the-office-menu-and-re-purposing.aspx
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
<command idMso="ApplicationOptionsDialog" enabled="false"/>
</commands>
</customUI>
In PowerPoint/Office 2010 it can also be hidden; see http://www.rondebruin.nl/backstage.htm
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
<command idMso="ApplicationOptionsDialog" enabled="false"/>
</commands>
<backstage>
<button idMso="ApplicationOptionsDialog" visible="false"/>
</backstage>
</customUI>