I'm trying to repurpose the built in font selector for my own objects in PowerPoint (vsto add-in). I repurpose regular commands (bold, italic etc.) successfully using the ribbon xml.
I have a test that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Test">
<group id="MyGroup"
label="My Group">
<comboBox idMso="Font" label="ComboBox1" onChange="ChangeCallback"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
If I have a regular is instead of the idMso this callback works fine:
ChangeCallback(Office.IRibbonControl control, string text)
{
Debug.WriteLine("Changed");
}
The callback stops working when I use idMso="Font", but the comboBox works and I can use it to select font like normal.
I have tried the following callback with no luck.
ChangeCallback(Office.IRibbonControl control, string text, ref bool cancelDefault)
{
Debug.WriteLine("Changed");
}
When I repurpose commands I put it in the commands section of the xml instead of the ribbon, but having a comboBox element there is not allowed.
Any ideas on how to get this to work?
Related
How does one create a dynamic menu hierarchy using VSTO Ribbons (for Outlook 2016)?
The xml placeholder could look like this, but I need to add/remove a menu tree under the menu root (instead of dummySingle). It seems like there would need to be something like a "getDependents" callback for menu items.
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<contextMenus>
<contextMenu idMso="ContextMenuMailItem">
<menu id="Menu Root" label="Menu Root" >
<button id="dummySingle"
label="dummy"
onAction="DummyAction"/>
</menu >
</contextMenus>
</customUI>
You would need to look at Dynamic Menus for Office Ribbon. This would be great source for you to start with: Adding Custom Dynamic Menus to the Office Fluent User Interface. Your ribbon XML will looks like ...
<dynamicMenu id="dynamicMenu1"
label="Dynamic Menu"
getContent="GetContent" />
And on GetContent handler you will build dynamic menu contexts, may looks like ...
public string GetContent(IRibbonControl control)
{
StringBuilder MyStringBuilder = new StringBuilder(#"<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >");
MyStringBuilder.Append(#"<button id=""button1"" label=""Insert Text"" onAction=""OnAction"" imageMso=""SignatureLineInsert"" />");
MyStringBuilder.Append(#"<menuSeparator id=""menusep1"" getTitle=""GetTitle"" />");
MyStringBuilder.Append(#"<button id=""button2"" label=""Insert More Text"" onAction=""OnAction"" imageMso=""FileDocumentInspect"" />");
MyStringBuilder.Append(#"</menu>");
return MyStringBuilder.ToString();
}
More on Dynamic Menus: documentation for dynamicMenu
I have written some 4 to 5 macros for Excel 2010, now I want to add all of these macros into a Custom Tab in the Ribbon as buttons. But I want to install all the macros as one complete package (or add-in). I have successfully installed one macro by creating a CustomUI package with the help of Visual Studio, but I don't know how to add other macros to the same add-in.
It depends on where you've stored your macro. For instance if your macro is saved in a module (within the Add-in file), then you would add an event handler to call the function as specified in the CustomUI. For example I have two macros, one called 'PricingTaxable' and one called 'PricingPerformance'.
Events handlers in module:
Sub PricingTaxable_eventhandler(control As IRibbonControl)
PricingTaxable
End Sub
Sub PricingPerformance_eventhandler(control As IRibbonControl)
PricingPerformance
End Sub
And the CustomUI XML code (find the event handler and function names to know what to do):
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon>
<tabs>
<tab id="customTab" label="Pricing" insertAfterMso="TabHome">
<group id="customGroup1" label="Taxable Income">
<button id="customButton1" label="Taxable Income" size="large"
onAction="PricingTaxable_eventhandler" imageMso="PivotTableLayoutReportLayout" />
</group>
<group id="customGroup2" label="Performance Sheets">
<button id="customButton2" label="Performance" size="large"
onAction="PricingPerformance_eventhandler" imageMso="ChartTrendline" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Refer here for more help: https://erpcoder.wordpress.com/2012/05/30/how-to-create-a-custom-ribbon-addin-for-excel-2010/
I am trying to add an extra tab to the Word ribbon and have a couple buttons to invoke my own macros. I did the same thing with Excel and it worked fine. For some reason I can't get it to work in Word. I am using the Custom UI Editor. Here's the ribbon code.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="Pavel">
<group id="customGroup" label="Formatting">
<button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Just a very simple tab, with one button that calls the macro Callback().
I added a module to the Word file with the following code.
Sub Callback()
MsgBox ("Test")
End Sub
The macro runs fine on its one (hitting the play button in the editor) but when invoked via the button on the tab I get the following error:
Edit: It seems to do something with 1) public access to the module and 2) apparently the macro should be taking some argument similar to "control as ribboncontrol" or something like that. If you know where to find the documentation for this, please let me know.
A Ribbon button expects a Sub which takes a parameter:
Sub Callback(button As IRibbonControl)
MsgBox ("Test")
End Sub
http://msdn.microsoft.com/en-us/magazine/cc163469.aspx
I don't know what's causing this.
I've created a template with a lot of macro code in it. And I've used the Custom UI EDitor for Office 2007 applications to create a custom Tab in the Ribbon interface. In this tab I've got this button which is supposed to open a userform. The XML code for the button is this:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="CustomForm" label="CustomForm">
<group id="customuserdata" label="Custom Userdata">
<button id="openForm" label="Open userform" imageMso="OpenForm" size="large" onAction="openForm" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
And in the same Template I've got a Public Sub named openForm and it this I just run myForm.Show. It's in this sub that the error occurs "Run-Time error '9'. SubScript out of range". What could cause this?
The exact code of the Sub I'm trying to call is this:
Public Sub openForm(control As IRibbonControl)
FormAltData.Show ' This is where the debugger stops at'
End Sub
The error was caused by an Array I believe. I tried to access an array before it was even declared ^^ My bad :)
I am trying to dynamically add a new custom ribbon in a Word 2007 document following teh manual method described in this article :- http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx.
The article specifies the following :-
a) Create a XML file named customUI.xml which will contain the elements you want to display
in the tab and put the same in a folder named customUI.
b) Rename your Word 2007 document to .zip. Add the above "customUI" folder to the zip file.
c) Add the following relationship to the "_rels/rels" file in the .zip file :-
<Relationship Type="http://schemas.microsoft.com/office/2006/
relationships/ui/extensibility" Target="/customUI/customUI.xml"
Id="customUIRelID" />
Do we have some code sample to achieve the same using OpenXML SDK? For example, how to add the "RibbonExtensibilityPart" (which contains the ribbon XML) to the document?
EDIT :-
This is how I did the above mentioned steps:-
string documentFileName = <path of the docx file>;
string ribbonXml = <path of the ribbon XML file>;
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(documentFileName, true))
{
MainDocumentPart mainPart = myDoc.MainDocumentPart;
if (myDoc.GetPartsCountOfType<RibbonExtensibilityPart>() > 0)
myDoc.DeletePart(myDoc.GetPartsOfType<RibbonExtensibilityPart>().First());
RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(File.ReadAllText(ribbonXML));
myDoc.CreateRelationshipToPart(ribbonExtensibilityPart);
}
and I am able to see the new ribbon with the elements in it.
However, I have buttons in the ribbon and I want to add handle actions on those buttons. Following is what my Ribbon XML looks like :-
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="CustomTab" label="My Tab">
<group id="MyGroup" label="My Group" >
<button id="Button1" label="My Large Button"
size="large"/>
<button id="Button2" label="My Normal Button"
size="normal" *onAction="ThisDocument.MyOtherButtonMacro"* />
</group >
</tab>
</tabs>
</ribbon>
</customUI>
have a look at the "onAction="ThisDocument.MyOtherButtonMacro". I know I can write Macro function in the document. However, as the custom ribbon will be added dynamically on the server-side, I am not sure how I can add the macro dynamically. Could anyone help?